def _create_plot_component(): # Create some data numpts = 400 x = sort(random(numpts)) y = random(numpts) xs = ArrayDataSource(x, sort_order='ascending') ys = ArrayDataSource(y) vectorlen = 15 vectors = array((random(numpts)*vectorlen,random(numpts)*vectorlen)).T vector_ds = MultiArrayDataSource(vectors) xrange = DataRange1D() xrange.add(xs) yrange = DataRange1D() yrange.add(ys) quiverplot = QuiverPlot(index = xs, value = ys, vectors = vector_ds, index_mapper = LinearMapper(range=xrange), value_mapper = LinearMapper(range=yrange), bgcolor = "white") add_default_axes(quiverplot) add_default_grids(quiverplot) # 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(): 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 _create_draggable_plot_component(title, initial_values=None, on_change_functor=None): container = OverlayPlotContainer(padding = 30, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) if initial_values: x = initial_values[0] y = initial_values[1] else: # Create the initial X-series of data numpoints = 30 low = -5 high = 15.0 x = linspace(low, high, numpoints) y = jn(0, x) lineplot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[0]), width=2.0) lineplot.selected_color = 'none' scatter = ScatterPlot( index=lineplot.index, value=lineplot.value, index_mapper=lineplot.index_mapper, value_mapper=lineplot.value_mapper, color=tuple(COLOR_PALETTE[0]), marker_size=2, ) scatter.index.sort_order = 'ascending' scatter.bgcolor = 'white' scatter.border_visible = True add_default_grids(scatter) add_default_axes(scatter) scatter.tools.append(PanTool(scatter, drag_button='right')) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(scatter, tool_mode='box', always_on=False, drag_button=None) scatter.overlays.append(zoom) point_dragging_tool = PointDraggingTool(scatter) point_dragging_tool.on_change_functor = on_change_functor scatter.tools.append(point_dragging_tool) container.add(lineplot) container.add(scatter) # Add the title at the top container.overlays.append(PlotLabel(title, component=container, font='swiss 16', overlay_position='top')) container.mx = lineplot.index.get_data() container.my = lineplot.value.get_data() container.lineplot = lineplot 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 _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) y = jn(0, x) plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0) plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True add_default_grids(plot) add_default_axes(plot) # Add some tools plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add a dynamic label. This can be dragged and moved around using the # right mouse button. Note the use of padding to offset the label # from its data point. label = DataLabel(component=plot, data_point=(x[40], y[40]), label_position="top left", padding=40, bgcolor = "lightgray", border_visible=False) plot.overlays.append(label) tool = DataLabelTool(label, drag_button="right", auto_arrow_root=True) label.tools.append(tool) # Add some static labels. label2 = DataLabel(component=plot, data_point=(x[20], y[20]), label_position="bottom right", border_visible=False, bgcolor="transparent", marker_color="blue", marker_line_color="transparent", marker = "diamond", arrow_visible=False) plot.overlays.append(label2) label3 = DataLabel(component=plot, data_point=(x[80], y[80]), label_position="top", padding_bottom=20, marker_color="transparent", marker_size=8, marker="circle", arrow_visible=False) plot.overlays.append(label3) container.add(plot) return container
def _refresh_container( self ): ''' rebuild the container for the current data ''' broadcaster = BroadcasterTool() mfn_line = self.value # print self.panel.GetSize() 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) y = ArrayDataSource(mfn_line.ydata, 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(y) value_mapper = LinearMapper(range=value_range) styles_m = adapter.line_style.values() line_style = styles_m[0] line_color = adapter.line_color[0] line_plot = self.lplot = LinePlot(index = index, value = y, index_mapper = index_mapper, value_mapper = value_mapper, color = line_color, width = 25, edge_color = 'blue', linestyle = line_style, border_visible = False) add_default_grids(line_plot) add_default_axes(line_plot, vtitle="Y", htitle="X") self.plot_container.add(line_plot) line_plot.tools.append(PanTool(line_plot)) line_plot.overlays.append(ZoomTool(line_plot))
def _create_spectrumplot(self, x, y): spectrumplot = create_line_plot((x, y), index_bounds=None, value_bounds=None, orientation='v', color='green', width=1.0, dash='solid', value_mapper_class=LinearMapper, bgcolor='transparent', border_visible=True, add_grid=False, add_axis=False, index_sort='ascending') add_default_axes(spectrumplot, orientation='flipped', vtitle='Frequency [MHz]', htitle='Amplitude') spectrumplot.origin = "top left" spectrumplot.tools.append(PanTool(spectrumplot, drag_button="right")) zoom = SimpleZoom(component=spectrumplot, tool_mode="box", drag_button="left", always_on=True) spectrumplot.overlays.append(zoom) container = OverlayPlotContainer(padding=40, padding_left=60) container.add(spectrumplot) self.container = container
def _create_window(self): self._create_data() x = self.x_values[:self.current_index] y = self.y_values[:self.current_index] value_range = None index_range = None plot = create_line_plot((x,y), color="red", width=2.0) value_range = plot.value_mapper.range index_range = plot.index_mapper.range index_range.low = -5 index_range.high = 15 plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot) hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 2.0 vgrid.grid_interval = 2.0 self.plot = plot plot.tools.append(PanTool(component=plot)) plot.overlays.append(ZoomTool(component=plot, tool_mode="box", always_on=False)) # Set the timer to generate events to us timerId = wx.NewId() self.timer = wx.Timer(self, timerId) self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId) self.timer.Start(50.0, wx.TIMER_CONTINUOUS) return Window(self, -1, component=plot)
def _create_plot_component(): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 30 low = -5 high = 15.0 x = linspace(low, high, numpoints) y = jn(0, x) lineplot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0) lineplot.selected_color = "none" scatter = ScatterPlot(index = lineplot.index, value = lineplot.value, index_mapper = lineplot.index_mapper, value_mapper = lineplot.value_mapper, color = tuple(COLOR_PALETTE[0]), marker_size = 5) scatter.index.sort_order = "ascending" scatter.bgcolor = "white" scatter.border_visible = True add_default_grids(scatter) add_default_axes(scatter) scatter.tools.append(PanTool(scatter, drag_button="right")) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(scatter, tool_mode="box", always_on=False, drag_button=None) scatter.overlays.append(zoom) scatter.tools.append(PointDraggingTool(scatter)) container.add(lineplot) container.add(scatter) # Add the title at the top container.overlays.append(PlotLabel("Line Editor", component=container, font = "swiss 16", overlay_position="top")) return container
def _create_traceplot(self, y=None): x = self.x if y == None: y = self.y traceplot = create_line_plot((x, y), index_bounds=None, value_bounds=None, orientation='v', color='blue', width=1.0, dash='solid', value_mapper_class=LinearMapper, bgcolor='transparent', border_visible=True, add_grid=False, add_axis=False, index_sort='ascending') add_default_axes(traceplot, orientation='flipped', vtitle='Time [ns]', htitle='Signal') traceplot.origin = "top left" traceplot.tools.append(PanTool(traceplot, drag_button="right")) zoom = SimpleZoom(component=traceplot, tool_mode="box", drag_button="left", always_on=True) traceplot.overlays.append(zoom) container = OverlayPlotContainer(padding=40, padding_left=60) container.add(traceplot) self.container = container
def _create_plot_component(): numpoints = 100 low = -5 high = 15.001 x = arange(low, high, (high-low)/numpoints) # Plot a bessel function y = jn(0, x) plot = create_line_plot((x,y), color=(0,0,1,1), width=2.0, index_sort="ascending") value_range = plot.value_mapper.range plot.active_tool = RangeSelection(plot, left_button_selects = True) plot.overlays.append(RangeSelectionOverlay(component=plot)) plot.bgcolor = "white" plot.padding = 50 add_default_grids(plot) add_default_axes(plot) return plot
def _create_plot_component(use_downsampling=False): container = OverlayPlotContainer(padding=40, bgcolor="lightgray", use_backbuffer = True, border_visible = True, fill_padding = True) numpoints = 100000 low = -5 high = 15.0 x = arange(low, high+0.001, (high-low)/numpoints) # Plot some bessel functionsless ../en value_mapper = None index_mapper = None for i in range(10): y = jn(i, x) plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.use_downsampling = use_downsampling if value_mapper is None: index_mapper = plot.index_mapper value_mapper = plot.value_mapper add_default_grids(plot) add_default_axes(plot) 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%2 == 1: plot.line_style = "dash" plot.bgcolor = "white" container.add(plot) selection_overlay = RangeSelectionOverlay(component = plot) plot.tools.append(RangeSelection(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(selection_overlay) plot.overlays.append(zoom) return container
def create_plot(): container = OverlayPlotContainer( padding=50, fill_padding=True, bgcolor="lightgray") 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 for i in range(10): y = jn(i, x) plot = create_line_plot((x, y), color=(1.0 - i / 10.0, i / 10.0, 0, 1), width=2.0, index_sort="ascending") if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper add_default_axes(plot) add_default_grids(plot) 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 % 2 == 1: plot.line_style = "dash" container.add(plot) return container
def _create_complexspectrumplot(self, x, y1, y2): amplitudeplot = create_line_plot((x, y1), index_bounds=None, value_bounds=None, orientation='h', color='green', width=1.0, dash='solid', value_mapper_class=LinearMapper, bgcolor='white', border_visible=True, add_grid=False, add_axis=False, index_sort='ascending') add_default_axes(amplitudeplot, orientation='normal', htitle='Frequency [MHz]', vtitle='Amplitude') amplitudeplot.tools.append(PanTool(amplitudeplot, drag_button="right")) zoom = SimpleZoom(component=amplitudeplot, tool_mode="box", drag_button="left", always_on=True) amplitudeplot.overlays.append(zoom) phaseplot = create_line_plot((x, y2), index_bounds=None, value_bounds=None, orientation='h', color='red', width=1.0, dash='solid', value_mapper_class=LinearMapper, bgcolor='white', border_visible=True, add_grid=False, add_axis=False, index_sort='ascending') add_default_axes(phaseplot, orientation='normal', htitle='Frequency [MHz]', vtitle='Unwrapped phase') # phaseplot.tools.append(PanTool(phaseplot, drag_button="right")) zoom = SimpleZoom(component=phaseplot, tool_mode="box", drag_button="left", always_on=True, # enter_zoom_key=KeySpec('z') ) phaseplot.overlays.append(zoom) self.rangeselect = RangeSelection(phaseplot, left_button_selects=False) self.rangeselect.on_trait_change(self.phase_center, "selection_completed") phaseplot.active_tool = self.rangeselect phaseplot.overlays.append(RangeSelectionOverlay(component=phaseplot)) container = VPlotContainer(padding=40, padding_left=60, spacing=40) container.add(phaseplot) container.add(amplitudeplot) self.container = container
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) plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") # Tweak some of the plot properties plot1.title = "My First Line Plot" plot1.padding = 50 plot1.padding_top = 75 plot1.legend.visible = True x = linspace(-5, 15.0, 100) y = jn(5, x) foreign_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0) left, bottom = add_default_axes(foreign_plot) left.orientation = "right" bottom.orientation = "top" plot1.add(foreign_plot) # Attach some tools to the plot broadcaster = BroadcasterTool() broadcaster.tools.append(PanTool(plot1)) broadcaster.tools.append(PanTool(foreign_plot)) for c in (plot1, foreign_plot): zoom = ZoomTool(component=c, tool_mode="box", always_on=False) broadcaster.tools.append(zoom) plot1.tools.append(broadcaster) return plot1
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 ): ''' 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 i=0 # for colors # plots = {} # for legend # index = ArrayDataSource(mfn_line.xdata) #****************************************** Massivbau Table x = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.296, 0.30, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.371 ] index = ArrayDataSource(x) index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D( low_setting = 0.0 ) vector1 = [0.030, 0.044, 0.055, 0.066, 0.076, 0.086, 0.097, 0.107, 0.118, 0.131, 0.145, 0.159, 0.173, 0.188, 0.202, 0.217, 0.232, 0.248, 0.250, 0.264, 0.280, 0.296, 0.312, 0.329, 0.346, 0.364, 0.382, 0.400, 0.419, 0.438, 0.450, 0.458, 0.478, 0.499, 0.520, 0.542, 0.565, 0.589, 0.614, 0.617] y1 = ArrayDataSource(vector1, sort_order="none") value_range.add(y1) value_mapper = LinearMapper(range=value_range) self.line_plot = LinePlot(index = index, value = y1, index_mapper = index_mapper, value_mapper = value_mapper, color = tuple(COLOR_PALETTE[i]), width = 20, edge_color = 'blue', border_visible = False) add_default_grids(self.line_plot) add_default_axes(self.line_plot, vtitle="x/d", htitle="x") self.plot_container.add(self.line_plot) # omega = [0.0101, 0.0203, 0.0306, 0.0410, 0.0515, 0.0621, 0.0728, 0.0836, 0.0946, 0.1057, 0.1170, 0.1285, 0.1401, 0.1518, 0.1638, 0.1759, 0.1882, 0.2007, 0.2024, 0.2134, 0.2263, 0.2395, 0.2529, 0.2665, 0.2804, 0.2946, 0.3091, 0.3239, 0.3391, 0.3546, 0.3643, 0.3706, 0.3869, 0.4038, 0.4211, 0.4391, 0.4576, 0.4768, 0.4968, 0.4994 ] # y_omega = ArrayDataSource(omega, sort_order="none") # value_range.add(y_omega) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y_omega, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="omega", htitle="x") # # self.plot_container.add(self.line_plot) # # # vector2 = [0.990, 0.985, 0.980, 0.976, 0.971, 0.967, 0.962, 0.956, 0.951, 0.946, 0.940, 0.934, 0.928, 0.922, 0.916, 0.910, 0.903, 0.897, 0.896, 0.890, 0.884, 0.877, 0.870, 0.863, 0.856, 0.849, 0.841, 0.834, 0.826, 0.818, 0.813, 0.810, 0.801, 0.793, 0.784, 0.774, 0.765, 0.755, 0.745, 0.743] # y2 = ArrayDataSource(vector2, sort_order="none") # value_range.add(y2) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y2, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="z/d", htitle="x") # self.plot_container.add(self.line_plot) # # # vector3 = [-0.77, -1.15, -1.46, -1.76, -2.06, -2.37, -2.68, -3.01, -3.35, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5, -3.5] # y3 = ArrayDataSource(vector3, sort_order="none") # value_range.add(y3) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y3, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="epsilon_c2", htitle="x") # # self.plot_container.add(self.line_plot) # # # vector4 = [25, 25, 25, 25, 25, 25, 25, 25, 25, 23.29, 20.71, 18.55, 16.73, 15.16, 13.80, 12.61, 11.55, 10.62, 10.50, 9.78, 9.02, 8.33, 7.71, 7.13, 6.60, 6.12, 5.67, 5.25, 4.86, 4.49, 4.28, 4.15, 3.82, 3.52, 3.23, 2.95, 2.69, 2.44, 2.20, 2.174] # y4 = ArrayDataSource(vector4, sort_order="none") # value_range.add(y4) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y4, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="epsilon_s1", htitle="x") # # self.plot_container.add(self.line_plot) # # # vector5 = 434.8 * ones(25)#[0.030, 0.044, 0.055, 0.066, 0.076, 0.876, 0.097, 0.107, 0.118, 0.131, 0.145, 0.159, 0.173, 0.188, 0.202, 0.217, 0.232, 0.248, 0.250, 0.264, 0.280, 0.296, 0.312, 0.329, 0.346, 0.364, 0.382, 0.400, 0.419, 0.438, 0.450, 0.458, 0.478, 0.499, 0.520, 0.542, 0.565, 0.589, 0.614, 0.617] # y5 = ArrayDataSource(vector5, sort_order="none") # value_range.add(y5) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y5, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="gamma_sd", htitle="x") # self.plot_container.add(self.line_plot) # # # vector6 = [0.337, 0.464, 0.553, 0.622, 0.676, 0.718, 0.751, 0.778, 0.801, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810, 0.810] # y6 = ArrayDataSource(vector6, sort_order="none") # value_range.add(y6) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y6, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="alpha_R", htitle="x") # # self.plot_container.add(self.line_plot) # # vector7 = [0.346, 0.353, 0.360, 0.368, 0.377, 0.387, 0.396, 0.405, 0.413, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416, 0.416] # y7 = ArrayDataSource(vector7, sort_order="none") # value_range.add(y7) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y7, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="K_a", htitle="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))
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 _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 i=0 # for colors # plots = {} # for legend # index = ArrayDataSource(mfn_line.xdata) #****************************************** Massivbau Table x = [0.30, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.50, 0.51, 0.52, 0.53, 0.54, 0.55 ] index = ArrayDataSource(x) index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D( low_setting = 0.0 ) # vector1 = [0.3684, 0.3789, 0.3894, 0.4000, 0.4105, 0.4210, 0.4316, 0.4421, 0.4526, 0.4631, 0.4737, 0.4842, 0.4947, 0.5052, 0.5158, 0.5263, 0.5368, 0.5473, 0.5579, 0.5684, 0.5789, 0.5894, 0.6000, 0.6105, 0.6210, 0.6316] # y1 = ArrayDataSource(vector1, sort_order="none") # value_range.add(y1) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y1, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.05 w1", htitle="x") # # self.plot_container.add(self.line_plot) # omega = [0.0041, 0.0146, 0.0252, 0.0357, 0.0462, 0.0567, 0.0673, 0.0778, 0.0883, 0.0988, 0.1094, 0.1199, 0.1304, 0.1410, 0.1515, 0.1620, 0.1725, 0.1831, 0.1936, 0.2041, 0.2146, 0.2252, 0.2357, 0.2462, 0.2567, 0.2673] # y_omega = ArrayDataSource(omega, sort_order="none") # value_range.add(y_omega) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y_omega, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.05 w2", htitle="x") # # self.plot_container.add(self.line_plot) # vector2 = [0.3686, 0.3797, 0.3908, 0.4020, 0.4131, 0.4242, 0.4353, 0.4464, 0.4575, 0.4686, 0.4797, 0.4908, 0.5020, 0.5131, 0.5242, 0.5353, 0.5464, 0.5575, 0.5686, 0.5797, 0.5908, 0.6020, 0.6131, 0.6242, 0.6353, 0.6464] # y2 = ArrayDataSource(vector2, sort_order="none") # value_range.add(y2) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y2, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.10 w1", htitle="x") # self.plot_container.add(self.line_plot) # vector3 = [0.0043, 0.0154, 0.0266, 0.0377, 0.0488, 0.0599, 0.0710, 0.0821, 0.0932, 0.1043, 0.1154, 0.1266, 0.1377, 0.1488, 0.1599, 0.1710, 0.1821, 0.1932, 0.2043, 0.2154, 0.2266, 0.2377, 0.2488, 0.2599, 0.2710, 0.2821] # y3 = ArrayDataSource(vector3, sort_order="none") # value_range.add(y3) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y3, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.10 w2", htitle="x") # # self.plot_container.add(self.line_plot) # vector4 = [0.3689, 0.3806, 0.3924, 0.4042, 0.4159, 0.4277, 0.4395, 0.4512, 0.4630, 0.4748, 0.4865, 0.4983, 0.5101, 0.5218, 0.5336, 0.5453, 0.5571, 0.5689, 0.5806, 0.5924, 0.6042, 0.6159, 0.6277, 0.6395, 0.6512, 0.6630 ] # y4 = ArrayDataSource(vector4, sort_order="none") # value_range.add(y4) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y4, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.15 w1", htitle="x") # # self.plot_container.add(self.line_plot) # vector5 = [0.0046, 0.0164, 0.0281, 0.0399, 0.0517, 0.0634, 0.0752, 0.0869, 0.0987, 0.1105, 0.1222, 0.1340, 0.1458, 0.1575, 0.1693, 0.1811, 0.1928, 0.2046, 0.2164, 0.2281, 0.2399, 0.2517, 0.2634, 0.2752, 0.2869, 0.2987] # y5 = ArrayDataSource(vector5, sort_order="none") # value_range.add(y5) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y5, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.15 w2", htitle="x") # self.plot_container.add(self.line_plot) vector6 = [0.3692, 0.3817, 0.3942, 0.4067, 0.4192, 0.4317, 0.4442, 0.4567, 0.4692, 0.4817, 0.4942, 0.5067, 0.5192, 0.5317, 0.5442, 0.5567, 0.5692, 0.5817, 0.5942, 0.6067, 0.6192, 0.6317, 0.6442, 0.6567, 0.6692, 0.6817] y6 = ArrayDataSource(vector6, sort_order="none") value_range.add(y6) value_mapper = LinearMapper(range=value_range) self.line_plot = LinePlot(index = index, value = y6, index_mapper = index_mapper, value_mapper = value_mapper, color = tuple(COLOR_PALETTE[i]), width = 20, edge_color = 'blue', border_visible = False) add_default_grids(self.line_plot) add_default_axes(self.line_plot, vtitle="d2/d=0.20 w1", htitle="x") self.plot_container.add(self.line_plot) # # vector7 = [0.0055, 0.0194, 0.0334, 0.0474, 0.0614, 0.0753, 0.0893, 0.1033, 0.1173, 0.1312, 0.1452, 0.1592, 0.1732, 0.1871, 0.2011, 0.2151, 0.2291, 0.2430, 0.2570, 0.2710, 0.2850, 0.2989, 0.3129, 0.3269, 0.3409, 0.3548] # y7 = ArrayDataSource(vector7, sort_order="none") # value_range.add(y7) # value_mapper = LinearMapper(range=value_range) # # self.line_plot = LinePlot(index = index, value = y7, # index_mapper = index_mapper, # value_mapper = value_mapper, # color = tuple(COLOR_PALETTE[i]), # width = 20, # edge_color = 'blue', # border_visible = False) # # add_default_grids(self.line_plot) # add_default_axes(self.line_plot, vtitle="d2/d=0.20 w2", htitle="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))
def add_plot(self, signal, sweep_point=None): ## waveform = signal.get_waveform() ## x = waveform.get_x()[-1][0].tolist() ## y = np.real(waveform.get_y()[0].tolist()) if sweep_point is None: sweep_point = signal.get_circuit()._sweep_set._points[0] trace = Trace(signal, self, self._next_color(), sweep_point) x_name = trace.index_label y_name = trace.label x = trace.get_indices() y = trace.get_values() if type(y[0]) == complex: y = [value.real for value in y] #print x_name, len(x) #print y_name, len(y) #print x #print y if self.firstplot: self.plotdata = ArrayPlotData() self.plotdata.set_data(x_name, x) self.plotdata.set_data(y_name, y) plot = Plot(self.plotdata) plot.padding = 1 plot.bgcolor = "white" plot.border_visible = True add_default_grids(plot) add_default_axes(plot) plot.tools.append(PanTool(plot)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = CustomZoomTool(plot) 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 #~ self.legend = Legend(component=plot, padding=10, align="ur") #~ self.legend.tools.append(LegendTool(self.legend, drag_button="right")) #~ plot.overlays.append(self.legend) #~ self.legend.plots = {} self.firstplot = False self.container.add(plot) self.plot = plot else: self.plotdata.set_data(x_name, x) self.plotdata.set_data(y_name, y) #self.plot.plot(self.plotdata.list_data()) pl = self.plot.plot( (x_name, y_name), name=trace.label, type="line", color=trace.color, line_style=trace.line_style, line_width=trace.line_width, marker=trace.marker, marker_size=trace.marker_size, marker_color=trace.marker_color) self.legend.plots[trace.label] = pl self.Refresh()
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) x = [0.01, 0.02, 0.03, 0.04, 0.05] index = ArrayDataSource(x) index_range = DataRange1D() index_range.add(index) index_mapper = LinearMapper(range=index_range) value_range = DataRange1D( low_setting = 0.0 ) i=0 # for colors plots = {} # for legend # pd = ArrayPlotData(index = mfn_line.xdata) # self.splot = Plot(pd) # for vector in ydata[:]: # vectors.append(vector) # # pd.set_data("y", vectors) # self.splot.plot(("index", "y"), color="red") # self.plot_container.add(self.splot) # for vector in ydata[:]: vector = [0.030, 0.044, 0.055, 0.066, 0.076] y = ArrayDataSource(vector, sort_order="none") #pd.set_data("y", vector) value_range.add(y) value_mapper = LinearMapper(range=value_range) # self.splot.plot(("index", "y"), color="red") self.line_plot = LinePlot(index = index, value = y, index_mapper = index_mapper, value_mapper = value_mapper, color = tuple(COLOR_PALETTE[i]), width = 20, edge_color = 'blue', border_visible = False) add_default_grids(self.line_plot) add_default_axes(self.line_plot, vtitle="force", htitle="displacement") 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))
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))
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(self): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = 0xc9e1eb, use_backbuffer=True) self.container = container self.value_mapper = None self.index_mapper = None self.plots = {} if sys.platform == 'linux2': plot_font = 'sans-serif' elif sys.platform == 'darwin': plot_font = 'Helvetica' else: plot_font = 'Verdana' # Store Python object ids to distinguish between different plots # with the same label self.plot_ids = [] self.beams = {} x = numpy.arange(0) y = numpy.arange(0) plot = create_line_plot((x,y), color=tuple(self.get_plot_color()), width=2.0) plot.index.sort_order = "ascending" plot.bgcolor = "white" plot.border_visible = True self.value_mapper = plot.value_mapper self.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, drag_button="middle")) # 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, drag_button="right", always_on_modifier='control')#, # x_min_zoom_factor=0.5, # y_min_zoom_factor=0.5, # x_max_zoom_factor=40., # y_max_zoom_factor=40.) zoom.zoom_factor = 1.2 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") # dragzoom.speed = 0.2 # plot.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable self.legend = Legend(component=plot, padding=10, align="ur") self.legend.tools.append(LegendTool(self.legend, drag_button="right")) self.legend.font = plot_font+' 12' plot.overlays.append(self.legend) self.legend.visible = False # The Legend tool allows plots to be selected by left clicking # on the label in the plot legend. This tool sets the ChacoPlot # selected plot trait. highlight_legend = HighlightLegend(self.legend) highlight_legend.parent = self self.legend.tools.append(highlight_legend) # The PlotSelectTool allows plots to be selected by left clicking # on the actual plot trace. This tools sets the ChacoPlot selected # plot trait. plot_select_tool = PlotSelectTool(self.container) plot_select_tool.parent = self plot.tools.append(plot_select_tool) plot.x_axis.title = "Distance (cm)" plot.x_axis.title_font = plot_font+" 12" plot.x_axis.tick_label_font = plot_font+" 10" plot.y_axis.title = "% Dose" plot.y_axis.title_font = plot_font+" 12" plot.y_axis.tick_label_font = plot_font+" 10" container.add(plot) # Set the list of plots on the legend self.legend.plots = self.plots # Add the title at the top self.title = PlotLabel("Scans", component=container, font = plot_font+' 16', overlay_position="top") container.overlays.append(self.title) return container