def __init__(self, x, y, color="blue", bgcolor="none", orientation="h"): self.y_values = y[:] if type(x) == ArrayDataSource: self.x_values = x.get_data()[:] plot = create_line_plot((x, self.y_values), color=color, bgcolor=bgcolor, add_grid=True, add_axis=True, orientation=orientation) else: self.x_values = x[:] plot = create_line_plot((self.x_values,self.y_values), color=color, bgcolor=bgcolor, add_grid=True, add_axis=True, orientation=orientation) plot.resizable = "" plot.bounds = [PLOT_SIZE, PLOT_SIZE] plot.unified_draw = True plot.tools.append(PanTool(plot, drag_button="right")) plot.tools.append(MoveTool(plot)) plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False)) self.plot = plot self.numpoints = len(self.x_values) self.current_index = self.numpoints/2 self.increment = 2
def _container_default(self): x = arange(-5.0, 15.0, 20.0 / 100) y = jn(0, x) left_plot = create_line_plot((x, y), bgcolor="white", add_grid=True, add_axis=True) left_plot.tools.append(PanTool(left_plot)) self.left_plot = left_plot y = jn(1, x) right_plot = create_line_plot((x, y), bgcolor="white", add_grid=True, add_axis=True) right_plot.tools.append(PanTool(right_plot)) right_plot.y_axis.orientation = "right" self.right_plot = right_plot # Tone down the colors on the grids right_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5) right_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5) left_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5) left_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5) container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray") container.add(left_plot) container.add(right_plot) return container
def _container_default(self): x = arange(-5.0, 15.0, 20.0/100) y = jn(0, x) left_plot = create_line_plot((x, y), bgcolor="white", add_grid=True, add_axis=True) left_plot.tools.append(PanTool(left_plot)) self.left_plot = left_plot y = jn(1, x) right_plot = create_line_plot((x, y), bgcolor="white", add_grid=True, add_axis=True) right_plot.tools.append(PanTool(right_plot)) right_plot.y_axis.orientation = "right" self.right_plot = right_plot # Tone down the colors on the grids right_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5) right_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5) left_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5) left_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5) container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray") container.add(left_plot) container.add(right_plot) return container
def __init__(self, x, y, color="blue", bgcolor="white"): self.y_values = y[:] if type(x) == ArrayDataSource: self.x_values = x.get_data()[:] plot = create_line_plot((x, self.y_values), color=color, bgcolor=bgcolor, add_grid=True, add_axis=True) else: self.x_values = x[:] plot = create_line_plot((self.x_values, self.y_values), color=color, bgcolor=bgcolor, add_grid=True, add_axis=True) plot.resizable = "" plot.bounds = [PLOT_SIZE, PLOT_SIZE] plot.unified_draw = True plot.tools.append(PanTool(plot, drag_button="right")) plot.tools.append(MoveTool(plot)) plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False)) self.plot = plot self.numpoints = len(self.x_values) self.current_index = self.numpoints / 2 self.increment = 2
def _dipole_plot_default(self): print('_dipole_plot_default') """Create the Plot instance.""" #pd = ArrayPlotData(index = self.dipole_data_model.x_index) #pd.set_data("y", self.dipole_data_model.data) plot = create_line_plot( (self.dipole_data_model.x_index, self.dipole_data_model.data), color='black') #plot.add(self.dipole_renderer) #plot.plot(("index", "y")) x_axis = PlotAxis(component=plot, mapper=plot.index_mapper, orientation='bottom') # # y_axis = PlotAxis(component=plot, # # mapper=self.signals_renderer.value_mapper, # # orientation='left') plot.overlays.extend([x_axis]) plot.index = self.signals_renderer.index plot.overlays.append( LineInspector(plot, write_metadata=True, is_listener=True)) # plot.overlays.append(LineInspector(plot, axis="value", # is_listener=True)) plot.origin_axis_visible = False plot.padding_top = 0 plot.padding_left = 0 plot.padding_right = 0 plot.padding_bottom = 50 plot.border_visible = False plot.bgcolor = "white" plot.use_downsampling = True return plot
def init(self, parent): factory = self.factory container = OverlayPlotContainer(bgcolor='transparent', padding=0, spacing=0) window = Window(parent, component=container) interval = self.high - self.low data = ([self.low, self.high], [0.5]*2) plot = create_line_plot(data, color='black', bgcolor="sys_window") plot.x_mapper.range.low = self.low - interval*0.1 plot.x_mapper.range.high = self.high + interval*0.1 plot.y_mapper.range.high = 1.0 plot.y_mapper.range.low = 0.0 range_selection = RangeSelection(plot, left_button_selects=True) # Do not allow the user to reset the range range_selection.event_state = "selected" range_selection.deselect = lambda x: None range_selection.on_trait_change(self.update_interval, 'selection') plot.tools.append(range_selection) plot.overlays.append(RangeKnobsOverlay(plot)) self.plot = plot container.add(self.plot) # To set the low and high, we're actually going to set the # 'selection' metadata on the line plot to the tuple (low,high). plot.index.metadata["selections"] = (0, 1.0) # Tell the editor what to display self.control = window.control self.control.SetSize((factory.width, factory.height))
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_window(self): self._create_data() x = self.x_values[:] y = self.y_values[:] plots = [] plot = create_line_plot((x,y), color="red", width=2.0) 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)) self.timer = Timer(50.0, self.onTimer) return Window(self, -1, component=plot)
def plot_core(self, main, core, ref_depth_line=None): ''' plot core info on main plot''' logger.debug('replotting main cores') loc_index, loc, dist = self.model.core_info_dict[core.core_id] # first plot vertical line y_range = main.value_range ys = np.array([y_range.low, y_range.high]) xs = ys * 0 + loc line = create_line_plot((xs, ys), color='lightgreen', width=CORE_LINE_WIDTH) line.origin = 'top left' line.index_range = main.index_range main.add(line) # then plot boundary layers as dots on line if ref_depth_line is None: ref_depth_line = self.model.survey_line.core_depth_reference if ref_depth_line: ref_depth = ref_depth_line.depth_array[loc_index] else: ref_depth = 0 layer_depths = core.layer_boundaries ys = ref_depth + layer_depths xs = ys * 0 + loc scatter = create_scatter_plot((xs, ys), color='darkgreen', marker='circle', marker_size=CORE_LINE_WIDTH + 1) scatter.origin = 'top left' scatter.value_range = main.value_range scatter.index_range = main.index_range old_scatter = main.plots.get('core_plot', []) if old_scatter: main.components.remove(old_scatter[0]) main.add(scatter) main.plots['core_plot'] = [scatter]
def add(self,series,limit=None): broadcaster = BroadcasterTool() for name,line in series._plot.line.items(): if limit is not None and name not in limit: continue if line.time==[]: print "Graph.add> empty:", name continue plot=create_line_plot((seconds(line.time),line.data),color=line.color) self.plot_area.add(plot) axis = PlotAxis(orientation="left", resizable="v", mapper = plot.y_mapper, bgcolor="white", title = name, title_color = line.color, title_spacing = -4.0, border_visible = True,) ## Visual style axis.bounds = [60,0] axis.padding_left = 1 axis.padding_right = 1 self.container.add(axis) ## Tools (attach to all for now) plot.tools.append(broadcaster) broadcaster.tools.append(PanTool(plot)) broadcaster.tools.append(DragZoom(plot,maintain_aspect_ratio=False,drag_button='right',restrict_domain=True))
def _single_param_plot(self): """Creates series of Bessel function plots""" for component in self.plot.components: self.plot.remove(component) self.plot.request_redraw() plots = {} self.clust_editor.interactive=False eval_points = np.floor(np.linspace(2,11,self.step_size)) original_parameter = getattr(self.clust_editor, self.param1_name) for tnum, tds in enumerate(self.clust_editor.track_sets): tds.interactive = False # Compute the sihlouette coefficient for each parameter value eval_results = [] for eval_param in eval_points: setattr(self.clust_editor, self.param1_name, int(eval_param)) try: eval_results.append(self.silhouette_coefficient(tds)) except Exception, e: print e eval_results.append(-2) _plot = create_line_plot((eval_points, np.array(eval_results)), color=tuple(COLOR_PALETTE[tnum]), width=2.0) if tnum == 0: value_mapper, index_mapper, legend = \ self._setup_plot_tools(_plot) else: self._setup_mapper(_plot, value_mapper, index_mapper) self.plot.add(_plot) plots[tds.name] = _plot
def _single_param_plot(self): """Creates series of Bessel function plots""" for component in self.plot.components: self.plot.remove(component) self.plot.request_redraw() plots = {} self.clust_editor.interactive = False eval_points = np.floor(np.linspace(2, 11, self.step_size)) original_parameter = getattr(self.clust_editor, self.param1_name) for tnum, tds in enumerate(self.clust_editor.track_sets): tds.interactive = False # Compute the sihlouette coefficient for each parameter value eval_results = [] for eval_param in eval_points: setattr(self.clust_editor, self.param1_name, int(eval_param)) try: eval_results.append(self.silhouette_coefficient(tds)) except Exception, e: print e eval_results.append(-2) _plot = create_line_plot((eval_points, np.array(eval_results)), color=tuple(COLOR_PALETTE[tnum]), width=2.0) if tnum == 0: value_mapper, index_mapper, legend = \ self._setup_plot_tools(_plot) else: self._setup_mapper(_plot, value_mapper, index_mapper) self.plot.add(_plot) plots[tds.name] = _plot
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 __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 x-y data series to plot plot_area = OverlayPlotContainer(border_visible=True) container = HPlotContainer(padding=50, bgcolor="transparent") #container.spacing = 15 x = linspace(-2.0, 10.0, 100) for i in range(5): color = tuple(COLOR_PALETTE[i]) y = jn(i, x) renderer = create_line_plot((x, y), color=color) plot_area.add(renderer) #plot_area.padding_left = 20 axis = PlotAxis( orientation="left", resizable="v", mapper=renderer.y_mapper, axis_line_color=color, tick_color=color, tick_label_color=color, title_color=color, bgcolor="transparent", title="jn_%d" % i, border_visible=True, ) axis.bounds = [60, 0] axis.padding_left = 10 axis.padding_right = 10 container.add(axis) if i == 4: # Use the last plot's X mapper to create an X axis and a # vertical grid x_axis = PlotAxis(orientation="bottom", component=renderer, mapper=renderer.x_mapper) renderer.overlays.append(x_axis) grid = PlotGrid(mapper=renderer.x_mapper, orientation="vertical", line_color="lightgray", line_style="dot") renderer.underlays.append(grid) # Add the plot_area to the horizontal container container.add(plot_area) # Attach some tools to the plot broadcaster = BroadcasterTool() for plot in plot_area.components: broadcaster.tools.append(PanTool(plot)) # Attach the broadcaster to one of the plots. The choice of which # plot doesn't really matter, as long as one of them has a reference # to the tool and will hand events to it. plot.tools.append(broadcaster) return 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 _plot_default(self): plot_data = ArrayPlotData(index=self.sigma, value=self.mu) self.plot_data = plot_data plot = Plot(data=plot_data) line = create_line_plot([self.sigma, self.mu], add_grid=True, value_bounds=(min(self.mean), max(self.mean)), add_axis=True, index_sort='ascending', orientation='h') scatter = create_scatter_plot( [np.sqrt(np.diag(self.covar)), np.squeeze(self.mean)], index_bounds=(line.index_range.low, line.index_range.high), value_bounds=(line.value_range.low, line.value_range.high), marker='circle', color='blue') plot.add(line) left, bottom = line.underlays[-2:] left.title = 'Return' bottom.title = 'Risk' plot.add(scatter) cursor = CursorTool(line, drag_button='left', color='blue') self.cursor = cursor #cursor.current_position = self.sigma[0], self.mu[0] line.overlays.append(cursor) line.tools.append(PanTool(line, drag_button='right')) #line.overlays.append(ZoomTool(line)) return plot
def _make_container(self): container = chaco.VPlotContainer(padding=40, spacing = 25) broadcaster = chaco_tools.BroadcasterTool() for i in range(3): self.data.append((chaco.ArrayDataSource([]), chaco.ArrayDataSource([]))) plot = chaco.create_line_plot((self.data[-1][0], self.data[-1][1]), add_grid=True, add_axis=True, border_visible=True) zoom = chaco_tools.ZoomTool(plot, tool_mode='range', axis='index') pan = chaco_tools.PanTool(plot, constrain=True, constrain_direction='x') range_selector = chaco_tools.RangeSelection(plot, axis='index', selection_mode='set', enable_resize=False, disable_left_mouse=True) broadcaster.tools.append(zoom) broadcaster.tools.append(pan) broadcaster.tools.append(range_selector) plot.overlays.append(chaco_tools.RangeSelectionOverlay(plot, axis='index')) plot.bgcolor = 'white' container.add(plot) container.tools.append(broadcaster) return container
def _setup_plots(self): """Creates series of Bessel function plots""" plots = {} x = arange(self.low, self.high + 0.001, (self.high - self.low) / self.numpoints) for i in range(self.num_funs): y = jn(i, x) if i % 2 == 1: plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0) else: plot = create_scatter_plot((x, y), color=tuple(COLOR_PALETTE[i])) if i == 0: value_mapper, index_mapper, legend = self._setup_plot_tools(plot) else: self._setup_mapper(plot, value_mapper, index_mapper) self.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.overlays.append(PlotLabel("Bessel functions", component=self, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container self.tools.append(TraitsTool(self))
def plot_core(self, main, core, ref_line, loc_index, loc): ''' plot core info on main plot''' # first plot vertical line y_range = main.value_range ys = np.array([y_range.low, y_range.high]) xs = ys * 0 + loc line = create_line_plot((xs, ys), color='lightgreen', width=CORE_LINE_WIDTH) line.origin = 'top left' line.index_range = main.index_range main.add(line) # then plot boundary layers as dots on line layer_depths = core.layer_boundaries ref_depth_line = self.model.get_ref_depth_line() if ref_depth_line: ref_depth = ref_depth_line.depth_array[loc_index] else: ref_depth = 0 ys = ref_depth + layer_depths xs = ys * 0 + loc scatter = create_scatter_plot((xs, ys), color='darkgreen', marker='circle', marker_size=CORE_LINE_WIDTH + 1) scatter.origin = 'top left' scatter.value_range = main.value_range scatter.index_range = main.index_range main.add(scatter)
def _create_plot_component(): numpoints = 100 low = -5 high = 15.0 x = arange(low, high, (high - low) / numpoints) container = container_class(resizable="hv", bgcolor="lightgray", fill_padding=True, padding=10) # Plot some bessel functions value_range = None for i in range(10): y = jn(i, x) plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0, orientation=plot_orientation) plot.origin_axis_visible = True plot.origin = "top left" plot.padding_left = 10 plot.padding_right = 10 plot.border_visible = True plot.bgcolor = "white" if value_range is None: value_range = plot.value_mapper.range else: plot.value_range = value_range value_range.add(plot.value) if i % 2 == 1: plot.line_style = "dash" container.add(plot) container.padding_top = 50 container.overlays.append( PlotLabel("Bessel Functions in a Strip Plot", component=container, font="swiss 16", overlay_position="top") ) return container
def setUp(self): values = numpy.arange(10) self.plot = create_line_plot((values, values)) self.plot.bounds = [100, 100] self.plot._window = self.create_mock_window() self.tool = BetterSelectingZoom(component=self.plot, always_on=True) self.plot.active_tool = self.tool self.plot.do_layout()
def setUp(self): values = numpy.arange(10) self.plot = create_line_plot((values, values)) self.plot.bounds = [100, 100] self.plot._window = self.create_mock_window() self.tool = BetterZoom(component=self.plot) self.plot.active_tool = self.tool self.plot.do_layout()
def _create_plot_component(title, initial_values=None, on_change_functor=None): #return OverlayPlotContainer() container = OverlayPlotContainer(padding = 25, 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_default(self): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = self.numpoints low = self.low high = self.high 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 _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_plot_component(): # Create some x-y data series to plot plot_area = OverlayPlotContainer(border_visible=True) container = HPlotContainer(padding=50, bgcolor="transparent") #container.spacing = 15 x = linspace(-2.0, 10.0, 100) for i in range(5): color = tuple(COLOR_PALETTE[i]) y = jn(i, x) renderer = create_line_plot((x, y), color=color) plot_area.add(renderer) #plot_area.padding_left = 20 axis = PlotAxis(orientation="left", resizable="v", mapper = renderer.y_mapper, axis_line_color=color, tick_color=color, tick_label_color=color, title_color=color, bgcolor="transparent", title = "jn_%d" % i, border_visible = True,) axis.bounds = [60,0] axis.padding_left = 10 axis.padding_right = 10 container.add(axis) if i == 4: # Use the last plot's X mapper to create an X axis and a # vertical grid x_axis = PlotAxis(orientation="bottom", component=renderer, mapper=renderer.x_mapper) renderer.overlays.append(x_axis) grid = PlotGrid(mapper=renderer.x_mapper, orientation="vertical", line_color="lightgray", line_style="dot") renderer.underlays.append(grid) # Add the plot_area to the horizontal container container.add(plot_area) # Attach some tools to the plot broadcaster = BroadcasterTool() for plot in plot_area.components: broadcaster.tools.append(PanTool(plot)) # Attach the broadcaster to one of the plots. The choice of which # plot doesn't really matter, as long as one of them has a reference # to the tool and will hand events to it. plot.tools.append(broadcaster) return container
def _create_plot_component_vertical(signals=Array, use_downsampling=False): # container = HPlotContainer(resizable = "hv", bgcolor="lightgray", # fill_padding=True, padding = 10) container = VPlotContainer(resizable="hv", bgcolor="lightgray", fill_padding=True, padding=50) nSignal, nSample = np.shape(signals) time = arange(nSample) value_range = None plots = {} for i in range(nSignal): plot = create_line_plot( (time, signals[i]), color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]), width=1.0, # orientation="v") orientation="h") plot.origin_axis_visible = True # plot.origin = "top left" plot.padding_left = 10 plot.padding_right = 10 plot.border_visible = False plot.bgcolor = "white" if value_range is None: value_range = plot.value_mapper.range else: plot.value_range = value_range value_range.add(plot.value) container.add(plot) plots["Corr fun %d" % i] = plot # 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) legend.plots = plots # container.padding_top = 50 container.overlays.append( PlotLabel("Correlation function", component=container, font="swiss 16", overlay_position="top")) # 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_component_vertical(signals=Array, use_downsampling=False): # container = HPlotContainer(resizable = "hv", bgcolor="lightgray", # fill_padding=True, padding = 10) container = VPlotContainer(resizable="hv", bgcolor="lightgray", fill_padding=True, padding=50) nSignal, nSample = np.shape(signals) time = arange(nSample) value_range = None plots = {} for i in range(nSignal): plot = create_line_plot((time, signals[i]), color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]), width=1.0, # orientation="v") orientation="h") plot.origin_axis_visible = True # plot.origin = "top left" plot.padding_left = 10 plot.padding_right = 10 plot.border_visible = False plot.bgcolor = "white" if value_range is None: value_range = plot.value_mapper.range else: plot.value_range = value_range value_range.add(plot.value) container.add(plot) plots["Corr fun %d" % i] = plot # 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) legend.plots = plots # container.padding_top = 50 container.overlays.append(PlotLabel("Correlation function", component=container, font="swiss 16", overlay_position="top")) # 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_component_overlay(signals, use_downsampling=False): container = OverlayPlotContainer(padding=40, bgcolor="lightgray", use_backbuffer=True, border_visible=True, fill_padding=True) nSignal, nSample = np.shape(signals) time = arange(nSample) value_mapper = None index_mapper = None plots = {} for i in range(nSignal): plot = create_line_plot( (time, signals[i]), color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]), 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" plots["Corr fun %d" % i] = plot container.add(plot) # 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) # legend.plots = plots # 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 init_plot(self): x = arange(100) y = arange(100) self.plothandle = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100)) self.plothandle.padding = 50 self.plothandle.fill_padding = True self.plothandle.bgcolor = "white" left, bottom = add_default_axes(self.plothandle, vtitle=self.ytitle, htitle="Time (s)") hgrid, vgrid = add_default_grids(self.plothandle) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 return self.plothandle
def _create_plot_component_overlay(signals, use_downsampling=False): container = OverlayPlotContainer(padding=40, bgcolor="lightgray", use_backbuffer=True, border_visible=True, fill_padding=True) nSignal, nSample = np.shape(signals) time = arange(nSample) value_mapper = None index_mapper = None plots = {} for i in range(nSignal): plot = create_line_plot((time, signals[i]), color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]), 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" plots["Corr fun %d" % i] = plot container.add(plot) # 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) # legend.plots = plots # 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_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) 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_plot_component(use_downsampling=True): 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 _plots_default(self): plotdata = self.get_data_sets() plots = Plot(plotdata) plotsDict = {} # plot background sonar image and impound lines xbounds = self.model.survey_rng_m ybounds = self.model.depth_m plots.img_plot("sonarimg", colormap=jet, xbounds=xbounds, ybounds=ybounds) ip = plots.plot(('impound1_X','impound1_Y'), type='line', marker='square') plotsDict['Impoundment line'] = ip plots.x_axis.title = 'Distance along survey line (m)' plots.y_axis.title = 'Depth (m)' # add core samples as scatter with separate y-axis corex = plotdata.get_data('coreX') corey = plotdata.get_data('coreY') scatter = create_scatter_plot((corex,corey), marker='diamond', color='red' ) scatter.index_range = plots.index_range axis = PlotAxis(scatter, orientation='right') axis.title = 'Core sample dist from survey line (m)' scatter.underlays.append(axis) plots.add(scatter) # create vertical line for indicating selected core sample position vals1 = [0 for x in corey] vline = create_line_plot((corey,vals1), color='blue', orientation='v') vline.value_range = scatter.index_range plots.add(vline) # Add Legend legend = Legend(component=plots, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="left")) legend.plots = plotsDict plots.overlays.append(legend) # Add tools scatter.tools.append(PickTool(scatter)) plots.tools.append(TraceTool(plots)) plots.tools.append(PanTool(plots)) plots.tools.append(ZoomTool(plots)) return plots
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 __init__(self, x, y, color="blue", bgcolor="white"): self.x_values = x[:] self.y_values = y[:] self.numpoints = len(self.x_values) plot = create_line_plot((self.x_values,self.y_values), color=color, bgcolor=bgcolor, add_grid=True, add_axis=True) plot.resizable = "" plot.bounds = [PLOT_SIZE, PLOT_SIZE] plot.tools.append(PanTool(plot, drag_button="right")) plot.tools.append(MoveTool(plot)) plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False)) plot.unified_draw = True self.plot = plot self.current_index = self.numpoints/2 self.increment = 2
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(1): 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 do_plotv(session, *args, **kw): """ Creates a list of plots from the data in ``*args`` and options in ``**kw``, according to the docstring on commands.plot(). """ sort = kw.get("sort", "none") sources_list = make_data_sources(session, sort, *args) plot_type = kw.get("type", "line") if plot_type == "scatter": plots = [create_scatter_plot(sources) for sources in sources_list] elif plot_type == "line": plots = [create_line_plot(sources) for sources in sources_list] else: raise ChacoShellError("Unknown plot type '%s'." % plot_type) for plot in plots: plot.orientation = kw.get("orientation", "h") return plots
def _create_plot_component(): numpoints = 100 low = -5 high = 15.0 x = arange(low, high, (high - low) / numpoints) container = container_class(resizable="hv", bgcolor="lightgray", fill_padding=True, padding=10) # Plot some bessel functions value_range = None for i in range(10): y = jn(i, x) plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0, orientation=plot_orientation) plot.origin_axis_visible = True plot.origin = "top left" plot.padding_left = 10 plot.padding_right = 10 plot.border_visible = True plot.bgcolor = "white" if value_range is None: value_range = plot.value_mapper.range else: plot.value_range = value_range value_range.add(plot.value) if i % 2 == 1: plot.line_style = "dash" container.add(plot) container.padding_top = 50 container.overlays.append( PlotLabel("Bessel Functions in a Strip Plot", component=container, font="swiss 16", overlay_position="top")) return container
def _create_window(self): self._create_data() x = self.x_values[:self.current_index] y = self.y_values[:self.current_index] plot = create_line_plot((x, y), color="red", width=2.0) 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)) self.timer = Timer(50.0, self.onTimer) return Window(self, -1, component=plot)
def do_plotv(session, *args, **kw): """ Creates a list of plots from the data in ``*args`` and options in ``**kw``, according to the docstring on commands.plot(). """ sort = kw.get("sort", "none") sources_list = make_data_sources(session, sort, *args) plot_type = kw.get("type", "line") if plot_type == "scatter": plots = [create_scatter_plot(sources) for sources in sources_list] elif plot_type == "line": plots = [create_line_plot(sources) for sources in sources_list] else: raise ChacoShellError, "Unknown plot type '%s'." % plot_type for plot in plots: plot.orientation = kw.get("orientation", "h") return plots
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_core_depths(self, slice_plot, core, ref_line, loc_index): ''' plot a set of core depths to the given slice plot set to not visible by default but then show when within show_core_range''' x_range = slice_plot.index_range xs = np.array([x_range.low, x_range.high]) ref_depth_line = self.model.get_ref_depth_line() if ref_depth_line: ref_depth = ref_depth_line.depth_array[loc_index] else: ref_depth = 0 for boundary in core.layer_boundaries: ys = xs * 0 + (ref_depth + boundary) line = create_line_plot((xs, ys), orientation='h', color='lightgreen', width=CORE_LINE_WIDTH) line.origin = 'top left' line.value_range = slice_plot.index_range self.core_plots_dict.setdefault(core.core_id, []).append(line) slice_plot.add(line)
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 add(self, series, limit=None): broadcaster = BroadcasterTool() for name, line in series._plot.line.items(): if limit is not None and name not in limit: continue if line.time == []: print "Graph.add> empty:", name continue plot = create_line_plot((seconds(line.time), line.data), color=line.color) self.plot_area.add(plot) axis = PlotAxis( orientation="left", resizable="v", mapper=plot.y_mapper, bgcolor="white", title=name, title_color=line.color, title_spacing=-4.0, border_visible=True, ) ## Visual style axis.bounds = [60, 0] axis.padding_left = 1 axis.padding_right = 1 self.container.add(axis) ## Tools (attach to all for now) plot.tools.append(broadcaster) broadcaster.tools.append(PanTool(plot)) broadcaster.tools.append( DragZoom(plot, maintain_aspect_ratio=False, drag_button='right', restrict_domain=True))
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_core_depths(self, slice_plot, core, ref_depth_line=None): ''' plot a set of core depths to the given slice plot set to not visible by default but then show when within show_core_range''' logger.debug('replotting slice cores') x_range = slice_plot.index_range xs = np.array([x_range.low, x_range.high]) loc_index, loc, dist = self.model.core_info_dict[core.core_id] if ref_depth_line is None: ref_depth_line = self.model.survey_line.core_depth_reference if ref_depth_line: ref_depth = ref_depth_line.depth_array[loc_index] else: ref_depth = 0 for boundary in core.layer_boundaries: ys = xs * 0 + (ref_depth + boundary) line = create_line_plot((xs, ys), orientation='h', color='lightgreen', width=CORE_LINE_WIDTH) line.origin = 'top left' line.value_range = slice_plot.index_range self.core_plots_dict.setdefault(core.core_id, []).append(line) slice_plot.add(line)
def _setup_plots(self): """Creates series of Bessel function plots""" plots = {} x = arange(self.low, self.high + 0.001, (self.high - self.low) / self.numpoints) for i in range(self.num_funs): y = jn(i, x) if i % 2 == 1: plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[i]), width=2.0) else: plot = create_scatter_plot((x, y), color=tuple(COLOR_PALETTE[i])) if i == 0: value_mapper, index_mapper, legend = \ self._setup_plot_tools(plot) else: self._setup_mapper(plot, value_mapper, index_mapper) self.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.overlays.append( PlotLabel("Bessel functions", component=self, font="swiss 16", overlay_position="top")) # Add the traits inspector tool to the container self.tools.append(TraitsTool(self))
def _plot_default(self): container = OverlayPlotContainer(padding=50, fill_padding=True, bgcolor="lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = self.numpoints low = self.low high = self.high x = linspace(low, high, numpoints + 1) 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", font='modern 14', 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) # This label uses label_style='bubble'. label4 = DataLabel(component=plot, data_point=(x[60], y[60]), border_padding=10, marker_color="red", marker_size=3, label_position=(20, 50), label_style='bubble', label_text="Something interesting", label_format="at x=%(x).2f, y=%(y).2f", font='modern 18', bgcolor=(1, 1, 0.75, 1), ) plot.overlays.append(label4) tool4 = DataLabelTool(label4, drag_button="right", auto_arrow_root=True) label4.tools.append(tool4) # Another 'bubble' label. This one sets arrow_min_length=20, so # the arrow is not drawn when the label is close to the data point. label5 = DataLabel(component=plot, data_point=(x[65], y[65]), border_padding=10, marker_color="green", marker_size=4, show_label_coords=False, label_style='bubble', label_position=(25, 5), label_text="Label with\narrow_min_length=20", border_visible=False, arrow_min_length=20, font='modern 14', bgcolor=(0.75, 0.75, 0.75, 1), ) plot.overlays.append(label5) tool5 = DataLabelTool(label5, drag_button="right", auto_arrow_root=True) label5.tools.append(tool5) container.add(plot) return container
def _create_plot_component(): container = GridContainer(padding=40, fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(3,3), spacing=(10,10)) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Roll (degrees)", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Pitch (degrees)", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,365)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Yaw (degrees)", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Gyro X", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Gyro Y", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Gyro Z", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) x = arange(100) y = arange(100) plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-1,35)) plot.padding = 50 plot.fill_padding = True plot.bgcolor = "white" left, bottom = add_default_axes(plot, vtitle="Battery Voltage (V)", htitle="Time (s)") hgrid, vgrid = add_default_grids(plot) bottom.tick_interval = 20.0 vgrid.grid_interval = 10.0 container.add(plot) 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
from chaco import api as chaco # First, we create two arrays of data, x and y. 'x' will be a sequence of # 100 points spanning the range -2pi to 2pi, and 'y' will be sin(x). numpoints = 100 step = 4*pi / numpoints x = arange(-2*pi, 2*pi+step/2, step) y = sin(x) # Now that we have our data, we can use a factory function to create the # line plot for us. Chaco provides a few factories to simplify creating common # plot types (line, scatter, etc.). In later tutorials we'll see what the # factories are actually doing, and how to manually assemble plotting # primitives in more powerful ways. For now, factories suit our needs. myplot = chaco.create_line_plot((x,y), bgcolor="white", add_grid=True, add_axis=True) # We now need to set the plot's size, and add a little padding for the axes. # (Normally, when Chaco plots are placed inside WX windows, the bounds are # set automatically by the window.) myplot.padding = 50 myplot.bounds = [400,400] def main(): # Now we create a canvas of the appropriate size and ask it to render # our component. (If we wanted to display this plot in a window, we # would not need to create the graphics context ourselves; it would be # created for us by the window.) plot_gc = chaco.PlotGraphicsContext(myplot.outer_bounds) plot_gc.render_component(myplot)
def _create_plot_component(): container = OverlayPlotContainer(padding=60, fill_padding=True, use_backbuffer=True, border_visible=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) if i == 0: add_default_grids(plot) left_axis, _ = add_default_axes(plot) left_axis.title = "Bessel j0, j2, j3" elif i != 1: # Map correctly j2 and j3 on the first plot's axis: plot0 = plots["Bessel j_0"] plot.index_mapper = plot0.index_mapper plot.value_mapper = plot0.value_mapper plot0.value_mapper.range.add(plot.value) # Create a pan/zoom 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. Do it only for each independent set of axis_mappers: if i in [0, 1]: pan = PanTool(component=plot) broadcaster.tools.append(pan) zoom = ZoomTool(component=plot) broadcaster.tools.append(zoom) 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) axis.title = "Bessel j1" # Add the broadcast tool to one of the renderers: adding it to the # container instead breaks the box mode of the ZoomTool: plot0 = plots["Bessel j_0"] plot0.tools.append(broadcaster) # Create a legend, with tools to move it around and highlight renderers: legend = Legend(component=container, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) legend.tools.append(LegendHighlighter(legend)) 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_default(self): container = OverlayPlotContainer(padding=50, fill_padding=True, bgcolor="lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = self.numpoints low = self.low high = self.high x = linspace(low, high, numpoints + 1) 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", font='modern 14', 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) # This label uses label_style='bubble'. label4 = DataLabel( component=plot, data_point=(x[60], y[60]), border_padding=10, marker_color="red", marker_size=3, label_position=(20, 50), label_style='bubble', label_text="Something interesting", label_format="at x=%(x).2f, y=%(y).2f", font='modern 18', bgcolor=(1, 1, 0.75, 1), ) plot.overlays.append(label4) tool4 = DataLabelTool(label4, drag_button="right", auto_arrow_root=True) label4.tools.append(tool4) # Another 'bubble' label. This one sets arrow_min_length=20, so # the arrow is not drawn when the label is close to the data point. label5 = DataLabel( component=plot, data_point=(x[65], y[65]), border_padding=10, marker_color="green", marker_size=4, show_label_coords=False, label_style='bubble', label_position=(25, 5), label_text="Label with\narrow_min_length=20", border_visible=False, arrow_min_length=20, font='modern 14', bgcolor=(0.75, 0.75, 0.75, 1), ) plot.overlays.append(label5) tool5 = DataLabelTool(label5, drag_button="right", auto_arrow_root=True) label5.tools.append(tool5) container.add(plot) 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 = 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 __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))