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, index_sort=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_window(self): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) self.container = container # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = arange(low, high+0.001, (high-low)/numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) if i%2 == 1: plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" else: plot = create_scatter_plot((x,y), color=tuple(COLOR_PALETTE[i])) plot.bgcolor = "white" plot.border_visible = True if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper add_default_grids(plot) add_default_axes(plot) plot.index_range.tight_bounds = False plot.index_range.refresh() plot.value_range.tight_bounds = False plot.value_range.refresh() else: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) if i==0: plot.tools.append(PanTool(plot)) # The ZoomTool tool is stateful and allows drawing a zoom # box to select a zoom region. zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # The DragZoom tool just zooms in and out as the user drags # the mouse vertically. dragzoom = DragZoom(plot, drag_button="right") plot.tools.append(dragzoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) container.add(plot) plots["Bessel j_%d"%i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("Bessel functions", component=container, font = "swiss 16", overlay_position="top")) container.overlays.append(PlotLabel("height",component=container,overlay_position="bottom")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return Window(self, -1, component=container)
def _create_plot_component(): container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True) # Create the initial X-series of data numpoints = 100 low = -5 high = 15.0 x = linspace(low, high, numpoints) now = time() timex = linspace(now, now+7*24*3600, numpoints) # Plot some bessel functions value_mapper = None index_mapper = None plots = {} for i in range(10): y = jn(i, x) if i%2 == 1: plot = create_line_plot((timex,y), color=tuple(COLOR_PALETTE[i]), width=2.0) plot.index.sort_order = "ascending" else: plot = create_scatter_plot((timex,y), color=tuple(COLOR_PALETTE[i])) plot.bgcolor = "white" plot.border_visible = True if i == 0: value_mapper = plot.value_mapper index_mapper = plot.index_mapper left, bottom = add_default_axes(plot) left.tick_generator = ScalesTickGenerator() bottom.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem()) add_default_grids(plot, tick_gen=bottom.tick_generator) else: plot.value_mapper = value_mapper value_mapper.range.add(plot.value) plot.index_mapper = index_mapper index_mapper.range.add(plot.index) if i==0: plot.tools.append(PanTool(plot)) zoom = ZoomTool(plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Add a legend in the upper right corner, and make it relocatable legend = Legend(component=plot, padding=10, align="ur") legend.tools.append(LegendTool(legend, drag_button="right")) plot.overlays.append(legend) container.add(plot) plots["Bessel j_%d"%i] = plot # Set the list of plots on the legend legend.plots = plots # Add the title at the top container.overlays.append(PlotLabel("Bessel functions", component=container, font = "swiss 16", overlay_position="top")) # Add the traits inspector tool to the container container.tools.append(TraitsTool(container)) return container