def _create_plot_component(): # Create some x-y data series to plot 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 plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True) plot1.legend.visible = True plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Create a second scatter plot of one of the datasets, linking its # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50, border_visible=True) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") # Create a container and add our plots container = HPlotContainer() container.add(plot1) container.add(plot2) return container
def _create_data(self, *names): numpoints = self.numpoints plotdata = ArrayPlotData(times=create_dates(numpoints)) for name in names: plotdata.set_data( name, cumprod(random.lognormal(0.0, 0.04, size=numpoints))) self.plotdata = plotdata
def _create_plot_component(): # Create some x-y data series to plot 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 plot1 = Plot(pd, padding=50) plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Add the scrollbar hscrollbar = PlotScrollBar(component=plot1, axis="index", resizable="h", height=15) plot1.padding_top = 0 hscrollbar.force_data_update() # Create a container and add our plots container = VPlotContainer() container.add(plot1) container.add(hscrollbar) return container
def createWindow(widget): ''' Example on creating a new plot window in the main window MDI-Area ''' 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()
def _ts_data_changed(self): """ Dataset has changed: update the plot. ENH: add the possibility to pass a dict to ArrayPlotData. """ print "data changed: updating the plot..." arr_data = ArrayPlotData() for k, v in self.ts_data.items(): arr_data.set_data(k, v) self.ts_plot = ToolbarPlot(arr_data) for i, k in enumerate([k for k in self.ts_data.keys() if k != "index"]): self.ts_plot.plot(("index", k), name=k, color=colors[i % len(colors)]) if self.index_is_dates: # Index was an array of datetime: overwrite the x axis self.ts_plot.x_axis = None x_axis = PlotAxis(self.ts_plot, orientation="bottom", tick_generator=ScalesTickGenerator( scale=CalendarScaleSystem())) self.ts_plot.overlays.append(x_axis) self.ts_plot.x_grid.tick_generator = x_axis.tick_generator if self.data_file: self.ts_plot.title = "Time series visualization from %s" % self.data_file else: self.ts_plot.title = "Time series visualization" attach_tools(self.ts_plot)
def _create_plot_component(): # Create a GridContainer to hold all of our plots container = GridContainer(padding=20, fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(3,3), spacing=(12,12)) # Create the initial series of data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index = x) # Plot some bessel functions and add the plots to our container for i in range(9): pd.set_data("y" + str(i), jn(i,x)) plot = Plot(pd) plot.plot(("index", "y" + str(i)), color=tuple(COLOR_PALETTE[i]), line_width=2.0, bgcolor = "white", border_visible=True) # Tweak some of the plot properties plot.border_width = 1 plot.padding = 10 # Set each plot's aspect ratio based on its position in the # 3x3 grid of plots. n,m = divmod(i, 3) plot.aspect_ratio = float(n+1) / (m+1) # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add to the grid container container.add(plot) return container
def plotImage(self, image, plot=None): '''Plots a tiff image. | image -- Image object | plot -- plot instance to be updated | if None, a plot instance will be created Returns the plot instance. ''' if plot == None: pd = ArrayPlotData() pd.set_data('imagedata', image.data) plot = Plot(pd, default_origin = "bottom left", padding=0) plot.bgcolor = 'white' plot.fixed_preferred_size = (100, 100) plot.x_axis.visible = False plot.y_axis.visible = False self.imageplot = plot imgPlot = plot.img_plot("imagedata", colormap=self.cmap, name='image')[0] self.imgPlot = imgPlot self.appendImageTools(imgPlot) else: plot.data.set_data('imagedata', image.data) plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0] plot.invalidate_and_redraw() return plot
class DataChooser(HasTraits): plot = Instance(Plot) data_name = Enum("jn0", "jn1", "jn2") traits_view = View(Item('data_name', label="Y data"), Item('plot', editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Data Chooser") def __init__(self): x = linspace(-5, 10, 100) self.data = {"jn0": jn(0, x), "jn1": jn(1, x), "jn2": jn(2, x)} # Create the data and the PlotData object self.plotdata = ArrayPlotData(x=x, y=self.data["jn0"]) # Create a Plot and associate it with the PlotData plot = Plot(self.plotdata) # Create a line plot in the Plot plot.plot(("x", "y"), type="line", color="blue") self.plot = plot def _data_name_changed(self, old, new): self.plotdata.set_data("y", self.data[self.data_name])
def _fuel_cycle_plot_component(x, y, x_name, y_name): # Create some data # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="line", marker="circle", index_sort="ascending", color="red", marker_size=3, bgcolor="white") # Tweak some of the plot properties plot.title = "Fuel Cycle Plot" plot.line_width = 0.5 plot.padding = 100 plot.x_axis.title = x_name plot.x_axis.title_font = "Roman 16" plot.x_axis.tick_label_font = "Roman 12" plot.y_axis.title = y_name plot.y_axis.title_font = "Roman 16" plot.y_axis.tick_label_font = "Roman 12" # 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) return plot
def __init__(self, index, data_series, **kw): super(MyPlot, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('data_series', data_series) self.plot = Plot(plot_data) self.plot.plot(('index', 'data_series'))
def _create_plot_component(): # Use n_gon to compute center locations for our polygons points = n_gon(center=(0,0), r=3, nsides=4) # Choose some colors for our polygons colors = {3:0xaabbcc, 4:'orange', 5:'yellow', 6:'lightgreen'} # Create a PlotData object to store the polygon data pd = ArrayPlotData() # Create a Polygon Plot to draw the regular polygons polyplot = Plot(pd) # Store path data for each polygon, and plot nsides = 3 for p in points: npoints = n_gon(center=p, r=2, nsides=nsides) nxarray, nyarray = transpose(npoints) pd.set_data("x" + str(nsides), nxarray) pd.set_data("y" + str(nsides), nyarray) plot = polyplot.plot(("x"+str(nsides), "y"+str(nsides)), type="polygon", face_color=colors[nsides], hittest_type="poly")[0] plot.tools.append(DataspaceMoveTool(plot, drag_button="left")) nsides = nsides + 1 # Tweak some of the plot properties polyplot.padding = 50 polyplot.title = "Polygon Plot" polyplot.x_axis.mapper.range.set(low=-10, high=10) polyplot.y_axis.mapper.range.set(low=-10, high=10) return polyplot
def _create_data(self, names): plotdata = ArrayPlotData(times = np.squeeze(dateArray)) i = 0 for name in names: plotdata.set_data(name, data[:,i]) i += 1 self.plotdata = plotdata
def _plot_default(self): # Create starting points for the vectors. numpts = self.numpts x = sort(random(numpts)) y = random(numpts) # Create vectors. vectorlen = self.vectorlen vectors = array((random(numpts)*vectorlen, random(numpts)*vectorlen)).T data = ArrayPlotData() data.set_data('index', x) data.set_data('value', y) data.set_data('vectors', vectors) quiverplot = Plot(data) quiverplot.quiverplot(('index', 'value', 'vectors')) # Attach some tools to the plot quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift")) zoom = ZoomTool(quiverplot) quiverplot.overlays.append(zoom) container = OverlayPlotContainer(quiverplot, padding=50) return container
def _create_plot_component(): # Create a GridContainer to hold all of our plots: 2 rows, 3 columns: container = GridContainer(padding=40, fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(2, 3), spacing=(20, 20)) # Create the initial series of data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index=x) # Plot some bessel functions and add the plots to our container for i in range(6): pd.set_data("y" + str(i), jn(i, x)) plot = Plot(pd) plot.plot(("index", "y" + str(i)), color=tuple(COLOR_PALETTE[i]), line_width=2.0, bgcolor="white", border_visible=True) # Tweak some of the plot properties plot.border_width = 1 plot.padding = 0 plot.padding_top = 30 # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add to the grid container ( container.add(plot) # Set the upper-left plot to only be resizable vertically, and to have a # fixed horizontal width. This also constrains the width of the first column. ul_plot = container.components[0] ul_plot.set(resizable="v", width=200) ul_plot.overlays.append( PlotLabel("Not horizontally resizable", component=ul_plot)) # Set the bottom center plot to have a fixed width and height. # This also constrains the height of the bottom row and the width of # the middle column. cplot = container.components[4] cplot.set(resizable="", bounds=[400, 400]) cplot.overlays.append(PlotLabel("Not resizable", component=cplot)) container.padding_top = 50 container.overlays.append( PlotLabel( 'Resize the window - some plots resize, others cannot ' '(see source code)', component=container, font="swiss 16", overlay_position="top")) return container
class DataChooser(HasTraits): plot = Instance(Plot) data_name = Enum("jn0", "jn1", "jn2") traits_view = View(Item("data_name", label="Y data"), Item("plot", editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Dynamic Plot Content") def __init__(self): super(DataChooser, self).__init__() x = linspace(-5, 10, 100) #jn is the Bessel function self.data = {"jn0": jn(0, x), "jn1": jn(1, x), "jn2": jn(2, x)} self.plotdata = ArrayPlotData(x=x, y=self.data["jn0"]) plot = Plot(self.plotdata) plot.plot(("x", "y"), type="line", color="blue") self.plot = plot def _data_name_changed(self): self.plotdata.set_data("y", self.data[self.data_name])
class DataChooser(HasTraits): plot = Instance(Plot) data_name = Enum("jn0", "jn1", "jn2") traits_view = View(Item('data_name', label="Y data"), Item('plot', editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Data Chooser") def __init__(self): x = linspace(-5, 10, 100) self.data = {"jn0": jn(0, x), "jn1": jn(1, x), "jn2": jn(2, x)} # Create the data and the PlotData object self.plotdata = ArrayPlotData(x=x, y=self.data["jn0"]) # Create a Plot and associate it with the PlotData plot = Plot(self.plotdata) # Create a line plot in the Plot plot.plot(("x", "y"), type="line", color="blue") self.plot = plot def _data_name_changed(self, old, new): self.plotdata.set_data("y", self.data[self.data_name])
def plotImage(self, image, plot=None): '''plot one image image: Image object plot: plot instance to be update, if None, a plot instance will be created return: plot instance''' if plot == None: pd = ArrayPlotData() pd.set_data('imagedata', image.data) plot = Plot(pd, default_origin = "bottom left", padding=0) #plot.title = image.name plot.bgcolor = 'white' plot.fixed_preferred_size = (100, 100) plot.x_axis.visible = False plot.y_axis.visible = False self.imageplot = plot # TODO: mess with color maps on else block imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0] self.imgPlot = imgPlot self._appendImageTools(imgPlot) #plot.overlays.append(MyLineDrawer(plot)) else: plot.data.set_data('imagedata', image.data) imgPlot = plot.plots['image'][0] #plot.title = image.name plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0] plot.invalidate_draw() return plot
def _create_plot_component(): # Create some data numpts = 500 x1 = random(numpts) y1 = random(numpts) x2 = x1 + standard_normal(numpts) * 0.05 y2 = y1 + standard_normal(numpts) * 0.05 # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", column_stack([x1, x2]).reshape(-1)) pd.set_data("value", column_stack([y1, y2]).reshape(-1)) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="segment", color="forestgreen", line_width=2, line_style='dash', alpha=0.7, bgcolor="white") # Tweak some of the plot properties plot.title = "Segment Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(self): selected = Event() # Create some x-y data series to plot 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 plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True) plot1.legend.visible = True plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) self.zoom = BetterSelectingZoom(component=plot1, tool_mode="box", always_on=False, selection_completed = selected) plot1.overlays.append(self.zoom) container = HPlotContainer() container.add(plot1) self.zoom.on_trait_change(self.selection_changed, 'ratio') return container
class DataChooser(HasTraits): plot = Instance(Plot) data_name = Enum("jn0", "jn1", "jn2") # default view for a traits class traits_view = View( Item('data_name', label="Y data"), Item('plot', editor=ComponentEditor(), show_label=False), width=800, height=600, resizable=True, title="Data Chooser") def _plot_default(self): x = linspace(-5, 10, 100) self.data = {"jn0": jn(0, x), "jn1": jn(1, x), "jn2": jn(2, x)} self.plotdata = ArrayPlotData(x = x, y = self.data["jn0"]) plot = Plot(self.plotdata) plot.plot(("x", "y"), type="line", color="blue") return plot # by default Enum trait displayed as a drop down menu def _data_name_changed(self): self.plotdata.set_data("y", self.data[self.data_name])
def test_highlight_on_log_plot(self): # test for bug: the highlight tool raises an exception when used on # a loglog plot x = np.linspace(1, 15, 200) plotdata = ArrayPlotData() plotdata.set_data("x", x) plotdata.set_data("y", x * x) plot = Plot(plotdata) plot.plot(("x", "y"), index_scale='log', value_scale='log') # necessary for the machinery involved in _find_curve plot.datasources["x"].sort_order = 'ascending' plot.datasources["y"].sort_order = 'ascending' # add the highlight tool htool = HighlightTool(plot, threshold=20.) plot.tools.append(htool) # we create a view of the plot so that the screen bounds are set pv = PlotViewer(plot=plot) pv.edit_traits() # this should not raise an exception event = MockEvent(x=170., y=60.) htool._find_curve(plot.plots['plot0'], event)
def __init__(self, index, series_a, series_b, series_c, **kw): super(PlotExample, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('series_a', series_a) plot_data.set_data('series_b', series_b) plot_data.set_data('series_c', series_c) self.plot = Plot(plot_data) self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8, color='auto') self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8, color='auto') self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8, color='auto') # set the plot's value range to 0, otherwise it may pad too much self.plot.value_range.low = 0 # replace the index values with some nicer labels label_axis = LabelAxis(self.plot, orientation='bottom', title='Months', positions=range(1, 10), labels=['jan', 'feb', 'march', 'april', 'may'], small_haxis_style=True) self.plot.underlays.remove(self.plot.index_axis) self.plot.index_axis = label_axis self.plot.underlays.append(label_axis)
def __init__(self): # The delegates views don't work unless we caller the superclass __init__ super(CursorTest, self).__init__() container = HPlotContainer(padding=0, spacing=20) self.plot = container # a subcontainer for the first plot. # I'm not sure why this is required. Without it, the layout doesn't work right. subcontainer = OverlayPlotContainer(padding=40) container.add(subcontainer) # make some data index = numpy.linspace(-10, 10, 512) value = numpy.sin(index) # create a LinePlot instance and add it to the subcontainer line = create_line_plot([index, value], add_grid=True, add_axis=True, index_sort="ascending", orientation="h") subcontainer.add(line) # here's our first cursor. csr = CursorTool(line, drag_button="left", color="blue") self.cursor1 = csr # and set it's initial position (in data-space units) csr.current_position = 0.0, 0.0 # this is a rendered component so it goes in the overlays list line.overlays.append(csr) # some other standard tools line.tools.append(PanTool(line, drag_button="right")) line.overlays.append(ZoomTool(line)) # make some 2D data for a colourmap plot xy_range = (-5, 5) x = numpy.linspace(xy_range[0], xy_range[1], 100) y = numpy.linspace(xy_range[0], xy_range[1], 100) X, Y = numpy.meshgrid(x, y) Z = numpy.sin(X) * numpy.arctan2(Y, X) # easiest way to get a CMapImagePlot is to use the Plot class ds = ArrayPlotData() ds.set_data("img", Z) img = Plot(ds, padding=40) cmapImgPlot = img.img_plot("img", xbounds=xy_range, ybounds=xy_range, colormap=jet)[0] container.add(img) # now make another cursor csr2 = CursorTool(cmapImgPlot, drag_button="left", color="white", line_width=2.0) self.cursor2 = csr2 csr2.current_position = 1.0, 1.5 cmapImgPlot.overlays.append(csr2) # add some standard tools. Note, I'm assigning the PanTool to the # right mouse-button to avoid conflicting with the cursors cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right")) cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))
def _create_plot_component(): # Create some data numpts = 5000 x = sort(random(numpts)) y = random(numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) # Tweak some of the plot properties plot.title = "Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component():# Create a scalar field to colormap xbounds = (-2*pi, 2*pi, 600) ybounds = (-1.5*pi, 1.5*pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs,ys) z = sin(x)*y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds = xbounds[:2], ybounds = ybounds[:2], colormap=jet)[0] # Tweak some of the plot properties plot.title = "My First Image Plot" plot.padding = 50 # 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) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool, bgcolor="white", border_visible=True) img_plot.overlays.append(overlay) return plot
def _create_plot_component(): # Create some x-y data series (with NaNs) to plot x = linspace(-5.0, 15.0, 500) x[75:125] = nan x[200:250] = nan x[300:330] = nan pd = ArrayPlotData(index = x) pd.set_data("value1", jn(0, x)) pd.set_data("value2", jn(1, x)) # Create some line and scatter plots of the data plot = Plot(pd) plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0) plot.plot(("index", "value2"), type="scatter", marker_size=1, name="j_1(x)", color="green") # Tweak some of the plot properties plot.title = "Plots with NaNs" plot.padding = 50 plot.legend.visible = True # 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) return plot
def plotImage(self, image, title, plot): '''plot one image image: 2d ndarray or ssp matrix title: string, plot title plot: plot instance to be update, if None, a plot instance will be created return: plot instance''' if plot == None: pd = ArrayPlotData() pd.set_data('imagedata', image) plot = Plot(pd, default_origin = "bottom left") plot.title = title plot.bgcolor = 'white' if not title == 'Total Intensity': plot.x_axis.visible = False plot.y_axis.visible = False imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0] # TODO: mess with color maps on else block else: imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0] self._appendTools(imgPlot, title) else: plot.data.set_data('imagedata', image) plot.title = title plot.aspect_ratio = float(image.shape[1]) / image.shape[0] plot.invalidate_draw() return plot
def __init__(self, index, data_series, **kw): super(MyPlot, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('data_series', data_series) self.plot = Plot(plot_data) self.plot.plot(('index', 'data_series'))
def _create_data(self, names): plotdata = ArrayPlotData(times=np.squeeze(dateArray)) i = 0 for name in names: plotdata.set_data(name, data[:, i]) i += 1 self.plotdata = plotdata
def _create_plot_component(): # Create some data numpts = 1000 x = numpy.arange(0, numpts) y = numpy.random.random(numpts) marker_size = numpy.random.normal(4.0, 4.0, numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="scatter", marker="circle", index_sort="ascending", color=(1.0, 0.0, 0.74, 0.4), marker_size=marker_size, bgcolor="white") # Tweak some of the plot properties plot.title = "Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
class Viewer1D(Viewer): image = Array result = Array def _reconstruction_default(self): rows, cols = self.image.shape[:2] self.plot_data = ArrayPlotData(original=self.image[0], reconstruction=self.result[0]) aspect = cols / float(rows) old = Plot(self.plot_data) old.plot('original', ) old.title = 'Old' self.new = Plot(self.plot_data) self.new.plot('reconstruction') self.new.title = 'New' container = HPlotContainer(bgcolor='none') container.add(old) container.add(self.new) return container def update_plot(self): self.plot_data.set_data('reconstruction', self.result[0]) self.new.request_redraw()
def _create_plot_component(): # Create some data numpts = 5000 x = sort(random(numpts)) y = random(numpts) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="scatter", marker="circle", index_sort="ascending", color="orange", marker_size=3, bgcolor="white") # Tweak some of the plot properties plot.title = "Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create a scalar field to colormap xbounds = (-2 * pi, 2 * pi, 600) ybounds = (-1.5 * pi, 1.5 * pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs, ys) z = sin(x) * y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=viridis)[0] # Tweak some of the plot properties plot.title = "Image Plot with Lasso" plot.padding = 50 lasso_selection = LassoSelection(component=img_plot) lasso_selection.on_trait_change(lasso_updated, "disjoint_selections") lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=img_plot) img_plot.tools.append(lasso_selection) img_plot.overlays.append(lasso_overlay) return plot
def _create_plot_component(): # Create a scalar field to colormap xbounds = (-2 * pi, 2 * pi, 600) ybounds = (-1.5 * pi, 1.5 * pi, 300) xs = linspace(*xbounds) ys = linspace(*ybounds) x, y = meshgrid(xs, ys) z = sin(x) * y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=jet)[0] # Tweak some of the plot properties plot.title = "Image Plot with Lasso" plot.padding = 50 lasso_selection = LassoSelection(component=img_plot) lasso_selection.on_trait_change(lasso_updated, "disjoint_selections") lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=img_plot) img_plot.tools.append(lasso_selection) img_plot.overlays.append(lasso_overlay) return plot
def _plot_default(self): # Create starting points for the vectors. numpts = self.numpts x = sort(random(numpts)) y = random(numpts) # Create vectors. vectorlen = self.vectorlen vectors = array( (random(numpts) * vectorlen, random(numpts) * vectorlen)).T data = ArrayPlotData() data.set_data('index', x) data.set_data('value', y) data.set_data('vectors', vectors) quiverplot = Plot(data) quiverplot.quiverplot(('index', 'value', 'vectors')) # Attach some tools to the plot quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift")) zoom = ZoomTool(quiverplot) quiverplot.overlays.append(zoom) container = OverlayPlotContainer(quiverplot, padding=50) return container
def updateplots(self): x = np.sort(np.random.random(100)) y = np.random.random(100) color = np.exp(-(x ** 2 + y ** 2)) # np.random.random(100) pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create some line plots of some of the data plot = Plot(pd) # Create a scatter plot and get a reference to it (separate from the # Plot object) because we'll need it for the regression tool below. scatterplot = plot.plot( ("index", "value", "color"), type="cmap_scatter", color_mapper=reverse(Spectral), marker="square", fill_alpha=0.9, marker_size=6, bgcolor=QtGui.QColor(240, 240, 240), )[0] # Tweak some of the plot properties plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, drag_button="right")) plot.overlays.append(ZoomTool(plot)) # Add the regression tool and overlay. These need to be added # directly to the scatterplot instance (and not the Plot instance). regression = RegressionLasso(scatterplot, selection_datasource=scatterplot.index) scatterplot.tools.append(regression) scatterplot.overlays.append(RegressionOverlay(scatterplot, lasso_selection=regression)) self.chaco_widget1.visualization.plot = plot self.chaco_widget2.visualization.plot = plot
def _create_plot_component(): # Create some RGBA image data image = zeros((200,400,4), dtype=uint8) image[:,0:40,0] += 255 # Vertical red stripe image[0:25,:,1] += 255 # Horizontal green stripe; also yellow square image[-80:,-160:,2] += 255 # Blue square image[:,:,3] = 255 # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", image) # Create the plot plot = Plot(pd, default_origin="top left") plot.x_axis.orientation = "top" img_plot = plot.img_plot("imagedata")[0] # Tweak some of the plot properties plot.bgcolor = "white" # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) plot.overlays.append(ZoomTool(component=plot, tool_mode="box", always_on=False)) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool)) return plot
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = randint(0, 7, numpts) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=accent, marker="square", fill_alpha=0.5, marker_size=6, outline_color="black", border_visible=True, bgcolor="white") # Tweak some of the plot properties plot.title = "Colormapped Scatter Plot with Range-selectable Data Points" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Right now, some of the tools are a little invasive, and we need the # actual ColomappedScatterPlot object to give to them cmap_renderer = plot.plots["my_plot"][0] # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35, selection_type="mask") cmap_renderer.overlays.append(selection) # Create the colorbar, handing in the appropriate range and colormap colorbar = create_colorbar(plot.color_mapper) colorbar.plot = cmap_renderer colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer=True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def __init__(self, index, series_a, series_b, series_c, **kw): super(PlotExample, self).__init__(**kw) plot_data = ArrayPlotData(index=index) plot_data.set_data('series_a', series_a) plot_data.set_data('series_b', series_b) plot_data.set_data('series_c', series_c) self.plot = Plot(plot_data) self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8, color='auto') self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8, color='auto') self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8, color='auto') # set the plot's value range to 0, otherwise it may pad too much self.plot.value_range.low = 0 # replace the index values with some nicer labels label_axis = LabelAxis(self.plot, orientation='bottom', title='Months', positions = list(range(1, 10)), labels = ['jan', 'feb', 'march', 'april', 'may'], small_haxis_style=True) self.plot.underlays.remove(self.plot.index_axis) self.plot.index_axis = label_axis self.plot.underlays.append(label_axis)
def _create_plot_component(): # Create a scalar field to colormap xs = linspace(0, 10, 600) ys = linspace(0, 5, 600) x, y = meshgrid(xs,ys) z = exp(-(x**2+y**2)/100) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata", xbounds=(0, 10), ybounds=(0, 5), colormap=jet)[0] # Tweak some of the plot properties plot.title = "My First Image Plot" plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False) img_plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create some RGBA image data image = zeros((200, 400, 4), dtype=uint8) image[:, 0:40, 0] += 255 # Vertical red stripe image[0:25, :, 1] += 255 # Horizontal green stripe; also yellow square image[-80:, -160:, 2] += 255 # Blue square image[:, :, 3] = 255 # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", image) # Create the plot plot = Plot(pd, default_origin="top left") plot.x_axis.orientation = "top" img_plot = plot.img_plot("imagedata")[0] # Tweak some of the plot properties plot.bgcolor = "white" # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) plot.overlays.append( ZoomTool(component=plot, tool_mode="box", always_on=False)) imgtool = ImageInspectorTool(img_plot) img_plot.tools.append(imgtool) plot.overlays.append( ImageInspectorOverlay(component=img_plot, image_inspector=imgtool)) return plot
def _create_plot_component(): # Create some x-y data series to plot 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 plot1 = Plot(pd, padding=50) plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Add the scrollbar hscrollbar = PlotScrollBar(component=plot1, axis="index", resizable="h", height=15) plot1.padding_top = 0 hscrollbar.force_data_update() # Create a container and add our plots container = VPlotContainer() container.add(plot1) container.add(hscrollbar) return container
def createWindow(widget): ''' Example on creating a new plot window in the main window MDI-Area ''' 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()
def _create_plot_component(): # Create some x-y data series (with NaNs) to plot x = linspace(-5.0, 15.0, 500) x[75:125] = nan x[200:250] = nan x[300:330] = nan pd = ArrayPlotData(index = x) pd.set_data("value1", jn(0, x)) pd.set_data("value2", jn(1, x)) # Create some line and scatter plots of the data plot = Plot(pd) plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0) plot.plot(("index", "value2"), type="scatter", marker_size=1, name="j_1(x)", color="green") # Tweak some of the plot properties plot.title = "Plots with NaNs" plot.padding = 50 plot.legend.visible = True # 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) return plot
def _create_plot_component(): # Create some x-y data series to plot 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 plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True) plot1.legend.visible = True plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Create a second scatter plot of one of the datasets, linking its # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50, border_visible=True) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") # Create a container and add our plots container = HPlotContainer() container.add(plot1) container.add(plot2) return container
def _plot_data_default(self): """Filling the ArrayPlotData before plotting""" data = ArrayPlotData() for i in range(self.polyg_nb): data.set_data("polyg"+str(i)+"_x", x_[i]) data.set_data("polyg"+str(i)+"_y", y_[i]) return data
class Plotter(): def __init__(self, parent): self.plotdata = ArrayPlotData(x=array([]), y=array([])) self.window = self.create_plot(parent) self.widget = self.window.control def update_data(self, x, y): self.plotdata.set_data("x", x) self.plotdata.set_data("y", y) def create_plot(self, 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, padding=[40,10,0,40], 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)
class Viewer1D(Viewer): image = Array result = Array def _reconstruction_default(self): rows, cols = self.image.shape[:2] self.plot_data = ArrayPlotData(original=self.image[0], reconstruction=self.result[0]) aspect = cols/float(rows) old = Plot(self.plot_data) old.plot('original', ) old.title = 'Old' self.new = Plot(self.plot_data) self.new.plot('reconstruction') self.new.title = 'New' container = HPlotContainer(bgcolor='none') container.add(old) container.add(self.new) return container def update_plot(self): self.plot_data.set_data('reconstruction', self.result[0]) self.new.request_redraw()
def _plot_default(self): # Create a GridContainer to hold all of our plots: 2 rows, 3 columns container = GridPlotContainer(shape=(2,3), spacing=(10,5), valign='top', bgcolor='lightgray') # Create x data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index = x) # Plot some Bessel functions and add the plots to our container for i in range(6): data_name = 'y{}'.format(i) pd.set_data(data_name, jn(i,x)) plot = Plot(pd) plot.plot(('index', data_name), color=COLOR_PALETTE[i], line_width=3.0) # Set each plot's aspect based on its position in the grid plot.set(height=((i % 3) + 1)*50, resizable='h') # Add to the grid container container.add(plot) return container
class Plotter(): def __init__(self, parent): self.plotdata = ArrayPlotData(x=array([]), y=array([])) self.window = self.create_plot(parent) self.widget = self.window.control def update_data(self, x, y): self.plotdata.set_data("x", x) self.plotdata.set_data("y", y) def create_plot(self, 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, padding=[40, 10, 0, 40], 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(self): """ Creates the plot component of the to be used in the FeatureScatter instance. """ x = np.zeros(len(self.data)) y = np.zeros(len(self.data)) c = np.zeros(len(self.data)) for i, (coord, count) in enumerate(self.data.items()): x[i], y[i] = coord c[i] = count c = np.log2(c) pd = ArrayPlotData() pd.set_data("x", x) pd.set_data("y", y) pd.set_data("color", c) cm = Map(DataRange1D(low=-c.max() / 2, high=c.max())) plot = Plot(pd) plot.plot(("x", "y", "color"), type="cmap_scatter", name="my_plot", marker="dot", index_sort="ascending", color_mapper=cm, marker_size=2, bgcolor=0xF7F7F7, ) plot.title = "Scatter Plot With Lasso Selection" plot.line_width = 1 plot.padding = 50 my_plot = plot.plots["my_plot"][0] my_plot.data = self.data my_plot.out_file = self.out_file my_plot.label = self.label lasso_selection = FeatureLasso(component=my_plot, selection_datasource=my_plot.index, drag_button="left") my_plot.tools.append(lasso_selection) my_plot.tools.append(BetterZoom(my_plot, zoom_factor=1.2)) my_plot.tools.append(PanTool(my_plot, drag_button="right")) my_plot.tools.append(ScatterInspector(my_plot)) lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=my_plot, selection_fill_color=0xEF8A62) my_plot.overlays.append(lasso_overlay) my_plot.overlays.append(ScatterInspectorOverlay(my_plot, hover_marker_size=4)) return plot
def _create_plot_component(): # Create some data numpts = 1000 x = numpy.arange(0, numpts) y = numpy.random.random(numpts) marker_size = numpy.random.normal(4.0, 4.0, numpts) color = numpy.random.random(numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Because this is a non-standard renderer, we can't call plot.plot, which # sets up the array data sources, mappers and default index/value ranges. # So, its gotta be done manually for now. index_ds = ArrayDataSource(x) value_ds = ArrayDataSource(y) color_ds = ArrayDataSource(color) # Create the plot plot = Plot(pd) plot.index_range.add(index_ds) plot.value_range.add(value_ds) # Create the index and value mappers using the plot data ranges imapper = LinearMapper(range=plot.index_range) vmapper = LinearMapper(range=plot.value_range) # Create the scatter renderer scatter = ColormappedScatterPlot( index=index_ds, value=value_ds, color_data=color_ds, color_mapper=jet(range=DataRange1D( low=0.0, high=1.0)), fill_alpha=0.4, index_mapper=imapper, value_mapper=vmapper, marker='circle', marker_size=marker_size) # Append the renderer to the list of the plot's plots plot.add(scatter) plot.plots['var_size_scatter'] = [scatter] # Tweak some of the plot properties plot.title = "Variable Size and Color Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create some data npts = 100 x = sort(random(npts)) y = random(npts) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("value2", y * 2) # Create the plot plot = Plot(pd) plot.plot(("index", "value"), type="scatter", name="my_plot", marker="circle", index_sort="ascending", color="slategray", marker_size=6, bgcolor="white") plot.plot(("index", "value2"), type="scatter", name="my_plot", marker="circle", index_sort="ascending", color="red", marker_size=6, bgcolor="white") # Tweak some of the plot properties plot.title = "Scatter Plot With Selection" plot.line_width = 1 plot.padding = 50 # Right now, some of the tools are a little invasive, and we need the # actual ScatterPlot object to give to them my_plot = plot.plots["my_plot"][0] # Attach some tools to the plot my_plot.tools.append( ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False)) my_plot.overlays.append( ScatterInspectorOverlay(my_plot, hover_color="transparent", hover_marker_size=10, hover_outline_color="purple", hover_line_width=2, selection_marker_size=8, selection_color="lawngreen")) my_plot.tools.append(PanTool(my_plot)) my_plot.overlays.append(ZoomTool(my_plot, drag_button="right")) return plot
def _create_plot_component(): # Create some data numpts = 1000 x = sort(random(numpts)) y = random(numpts) color = exp(-(x**2 + y**2)) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) pd.set_data("color", color) # Create the plot plot = Plot(pd) plot.plot(("index", "value", "color"), type="cmap_scatter", name="my_plot", color_mapper=jet, marker = "square", fill_alpha = 0.5, marker_size = 6, outline_color = "black", border_visible = True, bgcolor = "white") # Tweak some of the plot properties plot.title = "Colormapped Scatter Plot" plot.padding = 50 plot.x_grid.visible = False plot.y_grid.visible = False plot.x_axis.font = "modern 16" plot.y_axis.font = "modern 16" # Right now, some of the tools are a little invasive, and we need the # actual ColomappedScatterPlot object to give to them cmap_renderer = plot.plots["my_plot"][0] # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35, selection_type="mask") cmap_renderer.overlays.append(selection) # Create the colorbar, handing in the appropriate range and colormap colorbar = create_colorbar(plot.color_mapper) colorbar.plot = cmap_renderer colorbar.padding_top = plot.padding_top colorbar.padding_bottom = plot.padding_bottom # Create a container to position the plot and the colorbar side-by-side container = HPlotContainer(use_backbuffer = True) container.add(plot) container.add(colorbar) container.bgcolor = "lightgray" return container
def _create_plot_component(): # Create some data numpts = 1000 x = numpy.arange(0, numpts) y = numpy.random.random(numpts) marker_size = numpy.random.normal(4.0, 4.0, numpts) color = numpy.random.random(numpts) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("index", x) pd.set_data("value", y) # Because this is a non-standard renderer, we can't call plot.plot, which # sets up the array data sources, mappers and default index/value ranges. # So, its gotta be done manually for now. index_ds = ArrayDataSource(x) value_ds = ArrayDataSource(y) color_ds = ArrayDataSource(color) # Create the plot plot = Plot(pd) plot.index_range.add(index_ds) plot.value_range.add(value_ds) # Create the index and value mappers using the plot data ranges imapper = LinearMapper(range=plot.index_range) vmapper = LinearMapper(range=plot.value_range) # Create the scatter renderer scatter = ColormappedScatterPlot( index=index_ds, value=value_ds, color_data=color_ds, color_mapper=jet(range=DataRange1D(low=0.0, high=1.0)), fill_alpha=0.4, index_mapper = imapper, value_mapper = vmapper, marker='circle', marker_size=marker_size) # Append the renderer to the list of the plot's plots plot.add(scatter) plot.plots['var_size_scatter'] = [scatter] # Tweak some of the plot properties plot.title = "Variable Size and Color Scatter Plot" plot.line_width = 0.5 plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot, constrain_key="shift")) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
class DemoWindow(HasTraits): """ DemoWindow class contains the relevant information and functions for a single camera window: image, zoom, pan important members: _plot_data - contains image data to display (used by update_image) _plot - instance of Plot class to use with _plot_data """ _plot_data = Instance(ArrayPlotData) _plot = Instance(Plot) name = Str view = View(Item(name='_plot', editor=ComponentEditor(), show_label=False)) def __init__(self): """ Initialization of plot system """ padd = 25 self._plot_data = ArrayPlotData() self._plot = Plot(self._plot_data, default_origin="top left") self._plot.padding_left = padd self._plot.padding_right = padd self._plot.padding_top = padd self._plot.padding_bottom = padd self.right_p_x0, self.right_p_y0, self.right_p_x1, self.right_p_y1, self._quiverplots = [], [], [], [], [] def attach_tools(self): """ attach_tools(self) contains the relevant tools: clicker, pan, zoom """ pan = PanTool(self._plot, drag_button='middle') zoom_tool = ZoomTool(self._plot, tool_mode="box", always_on=False) # zoom_tool = BetterZoom(component=self._plot, tool_mode="box", always_on=False) zoom_tool.max_zoom_out_factor = 1.0 # Disable "bird view" zoom out self._img_plot.overlays.append(zoom_tool) self._img_plot.tools.append(pan) def update_image(self, image, is_float): """ update_image - displays/updates image in the curren camera window parameters: image - image data is_float - if true, displays an image as float array, else displays as byte array (B&W or gray) example usage: update_image(image,is_float=False) """ if is_float: # self._plot_data.set_data('imagedata',image.astype(np.float)) self._plot_data.set_data('imagedata', image.astype(np.float)) else: # self._plot_data.set_data('imagedata',image.astype(np.byte)) self._plot_data.set_data('imagedata', image) if not hasattr( self, '_img_plot'): # make a new plot if there is nothing to update print "inside 1" # self._img_plot=Instance(ImagePlot) self._img_plot = self._plot.img_plot('imagedata', colormap=gray)[0]
def _plot_data_default(self): plot_data = ArrayPlotData() plot_data.set_data('distance', np.zeros(50)) plot_data.set_data('potentiometer', np.zeros(50)) plot_data.set_data('switch', np.zeros(50)) plot_data.set_data('acc_x', np.zeros(50)) plot_data.set_data('acc_y', np.zeros(50)) plot_data.set_data('acc_z', np.zeros(50)) return plot_data