Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_plot_component():
# make 10 random points
x = arange(10)
x = ArrayDataSource(x, sort_order="ascending")
y = random_sample(10)
# Plot the data
pd = ArrayPlotData(x=x, y=y)
plot = Plot(pd)
plot.orientation = 'v'
line_plot = plot.plot(("x", "y"))[0]
# Add the tool to the plot both as a tool and as an overlay
tool = HittestTool(component=plot, line_plot=line_plot)
plot.tools.append(tool)
plot.overlays.append(tool)
return plot
def render_scatplot(self):
peakdata=ArrayPlotData()
peakdata.set_data("index",self.peaks[self.img_idx][:,0])
peakdata.set_data("value",self.peaks[self.img_idx][:,1])
peakdata.set_data("color",self.peaks[self.img_idx][:,2])
scatplot=Plot(peakdata,aspect_ratio=self.img_plot.aspect_ratio,default_origin="top left")
scatplot.plot(("index", "value", "color"),
type="cmap_scatter",
name="my_plot",
color_mapper=jet(DataRange1D(low = 0.0,
high = 1.0)),
marker = "circle",
fill_alpha = 0.5,
marker_size = 6,
)
scatplot.x_grid.visible = False
scatplot.y_grid.visible = False
scatplot.range2d=self.img_plot.range2d
self.scatplot=scatplot
self.peakdata=peakdata
return scatplot
def _create_plot_component(self):
# Create a plot data object and give it this data
self.pd = ArrayPlotData()
self.pd.set_data("imagedata", self.data[self.data_name])
# Create the plot
self.tplot = Plot(self.pd, default_origin="top left")
self.tplot.x_axis.orientation = "top"
self.tplot.img_plot("imagedata",
name="my_plot",
#xbounds=(0,10),
#ybounds=(0,10),
colormap=jet)
# Tweak some of the plot properties
self.tplot.title = "Matrix"
self.tplot.padding = 50
# Right now, some of the tools are a little invasive, and we need the
# actual CMapImage object to give to them
self.my_plot = self.tplot.plots["my_plot"][0]
# Attach some tools to the plot
def _create_plot_component():
# Create some x-y data series to plot
x = linspace(-2.0, 10.0, 40)
pd = ArrayPlotData(index = x, y0=jn(0,x))
# Create some line plots of some of the data
plot1 = Plot(pd, title="render_style = hold", padding=50, border_visible=True,
overlay_border = True)
plot1.legend.visible = True
lineplot = plot1.plot(("index", "y0"), name="j_0", color="red", render_style="hold")
# Attach some tools to the plot
attach_tools(plot1)
# Create a second scatter plot of one of the datasets, linking its
# range to the first plot
plot2 = Plot(pd, range2d=plot1.range2d, title="render_style = connectedhold",
padding=50, border_visible=True, overlay_border=True)
plot2.plot(('index', 'y0'), color="blue", render_style="connectedhold")
attach_tools(plot2)
# Create a container and add our plots
container = HPlotContainer()
def _plot_default(self, toolbar=True, **pltkwds):
''' Draw bare plot, including main plotting area, toolbar, etc...
either at initialization or global redo'''
if toolbar:
self.plot=ToolbarPlot(self.plotdata, **pltkwds)
else:
self.plot=Plot(self.plotdata, **pltkwds)
self.plot.title = self.title
self.plot.padding = 50
self.plot.legend.visible=False
self.plot.tools.append(PanTool(self.plot))
zoom=BetterSelectingZoom(component=self.plot, tool_mode="box", always_on=False)
self.plot.overlays.append(zoom)
def create_chaco_plot(parent):
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index = x)
for i in range(5):
pd.set_data("y" + str(i), jn(i,x))
# Create some line plots of some of the data
plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
plot.legend.visible = True
plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
plot.plot(("index", "y3"), name="j_3", color="blue")
# Attach some tools to the plot
plot.tools.append(PanTool(plot))
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
# This Window object bridges the Enable and Qt4 worlds, and handles events
# and drawing. We can create whatever hierarchy of nested containers we
# want, as long as the top-level item gets set as the .component attribute
# of a Window.
return Window(parent, -1, component = plot)
def _create_plot_component():
# Create the index
numpoints = 100
low = -5
high = 15.0
x = arange(low, high, (high - low) / numpoints)
plotdata = ArrayPlotData(x=x, y1=jn(0, x), y2=jn(1, x))
# Create the left plot
left_plot = Plot(plotdata)
left_plot.x_axis.title = "X"
left_plot.y_axis.title = "j0(x)"
renderer = left_plot.plot(("x", "y1"), type="line", color="blue",
width=2.0)[0]
renderer.overlays.append(LineInspector(renderer, axis='value',
write_metadata=True,
is_listener=True))
renderer.overlays.append(LineInspector(renderer, axis="index",
write_metadata=True,
is_listener=True))
left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range", alpha=0.1))
left_plot.tools.append(PanTool(left_plot))
# Create the right plot
right_plot = Plot(plotdata)
right_plot.index_range = left_plot.index_range
VGroup, HGroup
from chaco.api import Plot, AbstractPlotData, ArrayPlotData
from enable.component_editor import ComponentEditor
class InstanceUItem(UItem):
"""Convenience class for including an Instance in a View"""
style = Str('custom')
editor = Instance(InstanceEditor, ())
class PlotView(HasTraits):
"""Defines a sub-view whose size we wish to explicitly control."""
n = Int(123)
data = Instance(AbstractPlotData)
plot1 = Instance(Plot)
view = View(
# This HGroup keeps 'n' from over-widening, by implicitly placing
# a spring to the right of the item.
HGroup(Item('n')),
UItem('plot1', editor=ComponentEditor()),
resizable=True,
)
def create_plot(self, data, name, color):
p = Plot(self.data)
p.plot(data, name=name, color=color)
return p
def _data_changed(self):
self.plot1 = self.create_plot(("x", "y1"), "sin plot", "red")
import plotWidget
from PySide import QtGui
from numpy import linspace
from scipy.special import jn
from chaco.api import ArrayPlotData, Plot
window = widget.createNewWindow()
container = plotWidget.plotContainer(window)
plotWidget = plotWidget.PlotWidget(container)
container.setPlotWidget(plotWidget)
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index=x)
for i in range(5):
pd.set_data("y" + str(i), jn(i, x))
plot = Plot(pd, title=None, padding_left=60, padding_right=5, padding_top=5, padding_bottom=30, border_visible=True)
plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
plotWidget.setPlot(plot)
layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom)
layout.addWidget(container)
window.setLayout(layout)
window.show()