def add_legend(self, padding=10, align="ur"): legend = Legend(component=self.plot_container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) multibarplot = self.multibarplot legend.plots = dict(zip(multibarplot.legend_labels, multibarplot.barplots)) self.plot_container.overlays.append(legend)
def _create_plot_component(): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high+0.001, (high-low)/numpoints) # Plot some bessel functions plots = {} broadcaster = BroadcasterTool() for i in range(4): y = jn(i, x) plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True if i == 0: add_default_grids(plot) add_default_axes(plot) # Create a pan tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. pan = PanTool(plot) broadcaster.tools.append(pan) container.add(plot) plots["Bessel j_%d"%i] = plot # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. plot1 = plots["Bessel j_1"] axis = PlotAxis(plot1, orientation="right") plot1.underlays.append(axis) # Add the broadcast tool to the container, instead of to an # individual plot container.tools.append(broadcaster) legend = Legend(component=container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) container.overlays.append(legend) # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("Bessel functions", component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def _plot_targets_fired(self): print 'bla' numpoints = 100 low = -5 high = 15.0 x = np.arange(low, high+0.001, (high-low)/numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0) #plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True if i != 0: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) else: value_mapper = plot.value_mapper index_mapper = plot.index_mapper add_default_grids(plot) add_default_axes(plot) plot.index_range.tight_bounds = False plot.index_range.refresh() plot.value_range.tight_bounds = False plot.value_range.refresh() plot.tools.append(PanTool(plot)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # The DragZoom tool just zooms in and out as the user drags # the mouse vertically. dragzoom = DragZoom(plot, drag_button="right") plot.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) self.LinePlotContainer.add(plot) plots["Bessel j_%d"%i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top self.LinePlotContainer.overlays.append(PlotLabel("Bessel functions", component=self.LinePlotContainer, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container self.LinePlotContainer.tools.append(TraitsTool(self.LinePlotContainer)) self.show_lines=True print 'hallo'
def __init__(self): super(LinePlot, self).__init__() x = linspace(-14, 14, 100) y1 = sin(x) * x**3 y2 = cos(x) * x**3 plotdata = ArrayPlotData(x=x, y1=y1, y2=y2) plot = Plot(plotdata) plot.plot(("x", "y1"), type="line", color="blue", name="sin(x) * x**3") plot.plot(("x", "y2"), type="line", color="red", name="cos(x) * x**3") plot.plot(("x", "y2"), type="scatter", color="red", marker = "circle", marker_size = 2, name="cos(x) * x**3 points") plot.title = "Multiple Curves" self.plot = plot legend = Legend(padding=10, align="ur") legend.plots = plot.plots plot.overlays.append(legend)
def __init__(self): super(LinePlot, self).__init__() x = linspace(-14, 14, 100) y1 = sin(x) * x**3 y2 = cos(x) * x**3 plotdata = ArrayPlotData(x=x, y1=y1, y2=y2) plot = Plot(plotdata) plot.plot(("x", "y1"), type="line", color="blue", name="sin(x) * x**3") plot.plot(("x", "y2"), type="line", color="red", name="cos(x) * x**3") plot.plot(("x", "y2"), type="scatter", color="red", marker="circle", marker_size=2, name="cos(x) * x**3 points") plot.title = "Multiple Curves" self.plot = plot legend = Legend(padding=10, align="ur") legend.plots = plot.plots plot.overlays.append(legend)
def __init__(self, parent, id=-1, **kwargs): wx.Panel.__init__(self, parent, id=id, **kwargs) self.statusBar = self.GetTopLevelParent().statusBar self.container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) self.legend = Legend(component=self.container, padding=10, align="ur") #self.legend.tools.append(LegendTool(self.legend, drag_button="right")) self.container.overlays.append(self.legend) self.plot_window = Window(self, component=self.container) self.container.tools.append(TraitsTool(self.container)) self.firstplot = True self._palette = ['red', 'blue', 'green', 'purple', 'yellow'] self._current_palette_index = 0 self._traces = [] sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.plot_window.control, 1, wx.EXPAND) self.SetSizer(sizer) self.SetAutoLayout(True)
def _refresh_container( self ): ''' rebuild the container for the current data ''' broadcaster = BroadcasterTool() mfn_line = self.value ydata = transpose(mfn_line.ydata) adapter = self.adapter if adapter.var_x != '': # Get the x-label text from the object's trait var_x label_x = getattr( self.object, adapter.var_x ) else: # Get the x-label from the adapter label_x = adapter.label_x if adapter.var_y != '': label_y = getattr( self.object, adapter.var_y ) else: label_y = adapter.label_y index = ArrayDataSource(mfn_line.xdata) index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D( low_setting = 0.0 ) colors = [] colors = adapter.line_color #self.line_color_chaco.values() styles = [] styles = adapter.line_style #self.line_style_chaco.values() s_item = styles.items() color_chaco = [] style_chaco = [] c_index = 0 # loop for colors s_index = 0 # loop for styles i=0 # for colors and styles plots = {} # for legend pd = ArrayPlotData(index = mfn_line.xdata) self.splot = Plot(pd) for vector in ydata[:]: if len(colors) == c_index: c_index = 0 if len(styles) == s_index: s_index = 0 style_name = s_item[s_index][0] color_chaco.append(colors[c_index]) style_chaco.append(style_name) c_index = c_index + 1 s_index = s_index + 1 y = ArrayDataSource(vector, sort_order="none") value_range.add(y) value_mapper = LinearMapper(range=value_range) self.line_plot = LinePlot(index = index, value = y, index_mapper = index_mapper, value_mapper = value_mapper, color = color_chaco[i], line_width = adapter.linewidth, edge_color = 'blue', border_visible = False, line_style = style_chaco[i]) add_default_grids(self.line_plot) add_default_axes(self.line_plot, vtitle= label_y, htitle= label_x) self.plot_container.add(self.line_plot) # pan = PanTool(line_plot) # zoom = SimpleZoom(line_plot, tool_mode="box", always_on=False) # broadcaster.tools.append(pan) # broadcaster.tools.append(zoom) # Add the traits inspector tool to the container # # self.plot_container.tools.append(TraitsTool( self.plot_container )) self.line_plot.tools.append(PanTool(self.line_plot)) self.line_plot.overlays.append(ZoomTool(self.line_plot)) # Legend lgnd = adapter.legend_labels[i] plots[lgnd] = self.line_plot # change the color of the curves i = i +1 legend = Legend(component=self.plot_container, padding=10, align="ul") legend.tools.append(LegendTool(legend, drag_button="right")) self.plot_container.overlays.append(legend) # Set the list of plots on the legend legend.plots = plots # Add the title at the top self.plot_container.overlays.append(PlotLabel(adapter.title, component=self.plot_container, font = "swiss 16", overlay_position="top"))
def _create_window(self): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) self.container = container # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high+0.001, (high-low)/numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) if i%2 == 1: plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" else: plot = create_scatter_plot((x,y), color=tuple(COLOR_PALETTE[i])) plot.bgcolor = "white" plot.border_visible = True if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper add_default_grids(plot) add_default_axes(plot) plot.index_range.tight_bounds = False plot.index_range.refresh() plot.value_range.tight_bounds = False plot.value_range.refresh() else: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) if i==0: plot.tools.append(PanTool(plot)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # The DragZoom tool just zooms in and out as the user drags # the mouse vertically. dragzoom = DragZoom(plot, drag_button="right") plot.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) container.add(plot) plots["Bessel j_%d"%i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("Bessel functions", component=container, font = "swiss 16", overlay_position="top")) container.overlays.append(PlotLabel("height",component=container,overlay_position="bottom")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return Window(self, -1, component=container)
def _create_plot_component(): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = linspace(low, high, numpoints) now = time() timex = linspace(now, now+7*24*3600, numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) if i%2 == 1: plot = create_line_plot((timex,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" else: plot = create_scatter_plot((timex,y), color=tuple(COLOR_PALETTE[i])) plot.bgcolor = "white" plot.border_visible = True if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper left, bottom = add_default_axes(plot) left.tick_generator = ScalesTickGenerator() bottom.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem()) add_default_grids(plot, tick_gen=bottom.tick_generator) else: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) if i==0: plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) container.add(plot) plots["Bessel j_%d"%i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("Bessel functions", component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def _plot_container_default(self): container = OverlayPlotContainer( padding = 60, fill_padding = False, bgcolor = "white", use_backbuffer=True) # Plot some distribution functions plots = {} broadcaster = BroadcasterTool() #""" Plot # view = DataView(border_visible = True) # index = ArrayDataSource(self.x_array) value = ArrayDataSource(self.pdf_array, sort_order="none") index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D() value_range.add(value) value_mapper = LinearMapper(range=value_range) pdf_plot = FilledLinePlot(index = index, value = value, index_mapper = index_mapper, value_mapper = value_mapper, edge_color = tuple(COLOR_PALETTE[0]), face_color = "paleturquoise", bgcolor = "white", border_visible = True) add_default_grids(pdf_plot) add_default_axes(pdf_plot) #***************************Label************************************* pdf_label = DataLabel(component=pdf_plot, data_point=(2.4,0.15), label_position=(15,15), padding=5, label_format = 'PDF', bgcolor = "transparent", marker_color = "transparent", marker_line_color = "transparent", border_visible=False) pdf_plot.overlays.append(pdf_label) # tool = DataLabelTool(pdf_label, drag_button="right", auto_arrow_root=True) # pdf_label.tools.append(tool) container.add(pdf_plot) pan = PanTool(pdf_plot) zoom = SimpleZoom(pdf_plot, tool_mode="box", always_on=False) broadcaster.tools.append(pan) broadcaster.tools.append(zoom) #*********************************CDF**************************** plot = create_line_plot((self.x_array,self.pdf_array), color=tuple(COLOR_PALETTE[0]), width=2.0) plot.bgcolor = "white" plot.border_visible = True add_default_grids(plot) add_default_axes(plot) container.add(plot) # # Create a pan tool and give it a reference to the plot it should # # manipulate, but don't attach it to the plot. Instead, attach it to # # the broadcaster. pan = PanTool(plot) zoom = SimpleZoom(plot, tool_mode="box", always_on=False) broadcaster.tools.append(pan) broadcaster.tools.append(zoom) #""" PDF Plot # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. pdf_plot = create_line_plot((self.x_array,self.cdf_array), color=tuple(COLOR_PALETTE[1]), width=2.0) pdf_plot.bgcolor = "white" pdf_plot.border_visible = True # Label cdf_text = TextBoxOverlay(text = 'CDF', alternate_position = (200,390) ) pdf_plot.overlays.append(cdf_text) tool = DataLabelTool(cdf_text, drag_button="right", auto_arrow_root=True) cdf_text.tools.append(tool) container.add(pdf_plot) # vertical_axis = LabelAxis(pdf_plot, orientation='top', # title='Categories') # pdf_plot.underlays.append(vertical_axis) pdf_pan = PanTool(pdf_plot) pdf_zoom = SimpleZoom(pdf_plot, tool_mode="box", always_on=False) broadcaster.tools.append(pdf_pan) broadcaster.tools.append(pdf_zoom) axis = PlotAxis(pdf_plot, orientation="right") pdf_plot.underlays.append(axis) #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" # Add the broadcast tool to the container, instead of to an # individual plot container.tools.append(broadcaster) container.underlays.append(PlotLabel("CDF", component=container, font = "swiss 16", overlay_position="right")) legend = Legend(component=container, padding=10, align="ul") legend.tools.append(LegendTool(legend, drag_button="right")) container.overlays.append(legend) # Set the list of plots on the legend plots["pdf"] = plot plots["cdf"] = pdf_plot legend.plots = plots #******************************************************************************* x = ArrayDataSource( array( [ 0.0, 0.0 ], dtype = float ) ) y = ArrayDataSource( array( [ 0.0, self.mean ], dtype = float ) ) mean_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[2]), width=2.0) # vertical_plot = LinePlot(index = ArrayDataSource( array( [ 0.0, 1.0 ], dtype = float ) ), # value = ArrayDataSource( array( [ 0.0, 1.0 ], dtype = float ) ), # color = "green"), # index_mapper = LinearMapper(range=index_mapper), # value_mapper = LinearMapper(range=value_mapper)) container.add(mean_plot) # Create a pan tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. mean_pan = PanTool(mean_plot) mean_zoom = SimpleZoom(mean_plot, tool_mode="box", always_on=False) broadcaster.tools.append(mean_pan) broadcaster.tools.append(mean_zoom) #************************************************************************** x = ArrayDataSource( array( [ 0.0, 0.0 ], dtype = float ) ) y = ArrayDataSource( array( [ 0.0, 2.0 ], dtype = float ) ) print "self.standard_deviation", self.standard_deviation st_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[4]), width=2.0) container.add(st_plot) # Create a pan tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. st_pan = PanTool(st_plot) st_zoom = SimpleZoom(st_plot, tool_mode="box", always_on=False) broadcaster.tools.append(st_pan) broadcaster.tools.append(st_zoom) #***************************************************************************** # Add the title at the top container.overlays.append(PlotLabel("Distribution plots", component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container
def _refresh_container(self,container): """ Plot some distribution functions """ plots = {} broadcaster = BroadcasterTool() index = ArrayDataSource(self.x_array) value = ArrayDataSource(self.pdf_array, sort_order="none") index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D( low_setting = 0.0 ) value_range.add(value) value_mapper = LinearMapper(range=value_range) """Plot probability distribution function(pdf) with marking the area under the function """ plot_pdf = FilledLinePlot(index = index, value = value, index_mapper = index_mapper, value_mapper = value_mapper, edge_color = tuple(COLOR_PALETTE[0]), face_color = "paleturquoise", border_visible = True) """define the grid, axes and title of the vertical grid """ add_default_grids(plot_pdf) add_default_axes(plot_pdf, vtitle="PDF") """create a label for the pdf and append it to the plot_pdf """ label_pdf = DataLabel(component=plot_pdf, data_point=(2.4,0.13), label_position=(15,15), padding=5, label_format = 'PDF', bgcolor = "transparent", marker_color = "transparent", marker_line_color = "transparent", arrow_color = tuple(COLOR_PALETTE[0]), border_visible=False) plot_pdf.overlays.append(label_pdf) container.add(plot_pdf) """create a label for the x coordinate """ container.overlays.append(PlotLabel("X", component=container, font = "swiss 16", overlay_position="bottom")) pan = PanTool(plot_pdf) # zoom = SimpleZoom(plot_pdf, tool_mode="box", always_on=False) broadcaster.tools.append(pan) # broadcaster.tools.append(zoom) #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" #""" Mean Plot x = ArrayDataSource( array( [ self.mean, self.mean ], dtype = float ) ) y = ArrayDataSource( array( [ 0.0, max( self.pdf_array ) ], dtype = float ) ) """ Plot the mean value""" plot_mean = LinePlot(index = x, value = y, color = "pink", index_mapper = index_mapper, value_mapper = value_mapper ) container.add(plot_mean) # Create a pan tool and give it a reference to the plot it should # manipulate, but don't attach it to the plot. Instead, attach it to # the broadcaster. mean_pan = PanTool(plot_mean) # mean_zoom = SimpleZoom(plot_mean, tool_mode="box", always_on=False) broadcaster.tools.append(mean_pan) # broadcaster.tools.append(mean_zoom) #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" # Add an axis on the right-hand side that corresponds to the second plot. # Note that it uses plot.value_mapper instead of plot0.value_mapper. """ Plot cdf and its label """ plot_cdf = create_line_plot((self.x_array,self.cdf_array), color=tuple(COLOR_PALETTE[1]), width=2.0) plot_cdf.bgcolor = "white" plot_cdf.border_visible = True label_cdf = DataLabel(component=plot_cdf, data_point=(2.4,0.9), label_position=(-35,20), padding=5, label_format = 'CDF', bgcolor = "transparent", marker_color = "transparent", marker_line_color = "transparent", arrow_color = tuple(COLOR_PALETTE[1]), border_visible=False) plot_cdf.overlays.append(label_cdf) container.add(plot_cdf) pan1 = PanTool(plot_cdf) # zoom1 = SimpleZoom(plot_cdf, tool_mode="box", always_on=False) broadcaster.tools.append(pan1) # broadcaster.tools.append(zoom1) axis = PlotAxis(plot_cdf, title="CDF", orientation="right") plot_cdf.underlays.append(axis) #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" # Add the broadcast tool to the container, instead of to an # individual plot container.tools.append(broadcaster) ##************************************************************************** """Plot standard deviation """ stdev_low = self.mean - self.standard_deviation stdev_high = self.mean + self.standard_deviation stdev_low_height = self.distr.pdf( stdev_low ) stdev_high_height = self.distr.pdf( stdev_high ) x = ArrayDataSource( array( [ stdev_low, stdev_low, stdev_high, stdev_high ], dtype = float ) ) y = ArrayDataSource( array( [ 0, stdev_low_height, stdev_high_height, 0. ], dtype = float ) ) plot_st = PolygonPlot(index = x, value = y, edge_color = "purple", index_mapper = index_mapper, value_mapper = value_mapper ) container.add(plot_st) ##***************************************************************************** """create the legend for the mean """ legend = Legend(component=container, padding=10, align="ul") legend.tools.append(LegendTool(legend, drag_button="right")) container.overlays.append(legend) # Set the list of plots on the legend plots["Mean"] = plot_mean legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("probability distribution plots", component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container))