def _plot_default(self): # Create a GridContainer to hold all of our plots: 2 rows, 3 columns container = GridPlotContainer(shape=(2, 3), spacing=(10, 5), valign='top', bgcolor='lightgray') # Create x data x = linspace(-5, 15.0, 100) pd = ArrayPlotData(index=x) # Plot some Bessel functions and add the plots to our container for i in range(6): data_name = 'y{}'.format(i) pd.set_data(data_name, jn(i, x)) plot = Plot(pd) plot.plot(('index', data_name), color=COLOR_PALETTE[i], line_width=3.0) # Set each plot's aspect based on its position in the grid plot.height = ((i % 3) + 1) * 50.0 plot.resizable = 'h' # Add to the grid container container.add(plot) return container
def _plot_default(self): # Create data x = linspace(-5, 15.0, 100) y = jn(3, x) pd = ArrayPlotData(index=x, value=y) zoomable_plot = Plot(pd) zoomable_plot.plot(('index', 'value'), name='external', color='red', line_width=3) # Attach tools to the plot zoom = ZoomTool(component=zoomable_plot, tool_mode="box", always_on=False) zoomable_plot.overlays.append(zoom) zoomable_plot.tools.append(PanTool(zoomable_plot)) # Create a second inset plot, not resizable, not zoom-able inset_plot = Plot(pd) inset_plot.plot(('index', 'value'), color='blue') inset_plot.resizable = '' inset_plot.bounds = [250, 150] inset_plot.position = [450, 350] inset_plot.border_visible = True # Create a container and add our plots container = OverlayPlotContainer() container.add(zoomable_plot) container.add(inset_plot) return container
def main(): # 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 plot = Plot( pd, bgcolor="none", padding=30, border_visible=True, overlay_border=True, use_backbuffer=False) plot.legend.visible = True plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto") plot.plot(("index", "y3"), name="j_3", color="auto") plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Create the mlab test mesh and get references to various parts of the # VTK pipeline f = mlab.figure(size=(600, 500)) m = mlab.test_mesh() scene = mlab.gcf().scene render_window = scene.render_window renderer = scene.renderer rwi = scene.interactor plot.resizable = "" plot.bounds = [200, 200] plot.padding = 25 plot.bgcolor = "lightgray" plot.outer_position = [30, 30] plot.tools.append(MoveTool(component=plot, drag_button="right")) container = OverlayPlotContainer(bgcolor="transparent", fit_window=True) container.add(plot) # Create the Enable Window window = EnableVTKWindow( rwi, renderer, component=container, #istyle_class = tvtk.InteractorStyleSwitch, #istyle_class = tvtk.InteractorStyle, istyle_class=tvtk.InteractorStyleTrackballCamera, bgcolor="transparent", event_passthrough=True, ) mlab.show() return window, render_window
def main(): # 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 plot = Plot(pd, bgcolor="none", padding=30, border_visible=True, overlay_border=True, use_backbuffer=False) plot.legend.visible = True plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto") plot.plot(("index", "y3"), name="j_3", color="auto") plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) # Create the mlab test mesh and get references to various parts of the # VTK pipeline f = mlab.figure(size=(600,500)) m = mlab.test_mesh() scene = mlab.gcf().scene render_window = scene.render_window renderer = scene.renderer rwi = scene.interactor plot.resizable = "" plot.bounds = [200,200] plot.padding = 25 plot.bgcolor = "lightgray" plot.outer_position = [30,30] plot.tools.append(MoveTool(component=plot,drag_button="right")) container = OverlayPlotContainer(bgcolor = "transparent", fit_window = True) container.add(plot) # Create the Enable Window window = EnableVTKWindow(rwi, renderer, component=container, #istyle_class = tvtk.InteractorStyleSwitch, #istyle_class = tvtk.InteractorStyle, istyle_class = tvtk.InteractorStyleTrackballCamera, bgcolor = "transparent", event_passthrough = True, ) mlab.show() return window, render_window
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") plot1.plot(("index", "y3"), name="j_3", color="blue") # Tweak some of the plot properties plot1.title = "Inset Plot" plot1.padding = 50 # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) plot1.overlays.append(zoom) # Create a second scatter plot of one of the datasets, linking its # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, padding=50) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") plot2.resizable = "" plot2.bounds = [250, 250] plot2.position = [550, 150] plot2.bgcolor = "white" plot2.border_visible = True plot2.unified_draw = True plot2.tools.append(PanTool(plot2)) plot2.tools.append(MoveTool(plot2, drag_button="right")) zoom = ZoomTool(component=plot2, tool_mode="box", always_on=False) plot2.overlays.append(zoom) # Create a container and add our plots container = OverlayPlotContainer() container.add(plot1) container.add(plot2) return container
def clone_plot(clonetool, drop_position): # A little sketchy... canvas = clonetool.component.container.component.component # Create a new Plot object oldplot = clonetool.component newplot = Plot(oldplot.data) basic_traits = [ "orientation", "default_origin", "bgcolor", "border_color", "border_width", "border_visible", "draw_layer", "unified_draw", "fit_components", "fill_padding", "visible", "aspect_ratio", "title" ] for attr in basic_traits: setattr(newplot, attr, getattr(oldplot, attr)) # copy the ranges dst = newplot.range2d src = oldplot.range2d #for attr in ('_low_setting', '_low_value', '_high_setting', '_high_value'): # setattr(dst, attr, getattr(src, attr)) dst._xrange.sources = copy(src._xrange.sources) dst._yrange.sources = copy(src._yrange.sources) newplot.padding = oldplot.padding newplot.bounds = oldplot.bounds[:] newplot.resizable = "" newplot.position = drop_position newplot.datasources = copy(oldplot.datasources) for name, renderers in list(oldplot.plots.items()): newrenderers = [] for renderer in renderers: new_r = clone_renderer(renderer) new_r.index_mapper = LinearMapper(range=newplot.index_range) new_r.value_mapper = LinearMapper(range=newplot.value_range) new_r._layout_needed = True new_r.invalidate_draw() new_r.resizable = "hv" newrenderers.append(new_r) newplot.plots[name] = newrenderers #newplot.plots = copy(oldplot.plots) for name, renderers in list(newplot.plots.items()): newplot.add(*renderers) newplot.index_axis.title = oldplot.index_axis.title newplot.index_axis.unified_draw = True newplot.value_axis.title = oldplot.value_axis.title newplot.value_axis.unified_draw = True # Add new tools to the new plot newplot.tools.append( AxisTool(component=newplot, range_controller=canvas.range_controller)) # Add tools to the new plot pan_traits = [ "drag_button", "constrain", "constrain_key", "constrain_direction", "speed" ] zoom_traits = [ "tool_mode", "always_on", "axis", "enable_wheel", "drag_button", "wheel_zoom_step", "enter_zoom_key", "exit_zoom_key", "pointer", "color", "alpha", "border_color", "border_size", "disable_on_complete", "minimum_screen_delta", "max_zoom_in_factor", "max_zoom_out_factor" ] move_traits = [ "drag_button", "end_drag_on_leave", "cancel_keys", "capture_mouse", "modifier_key" ] if not MULTITOUCH: for tool in oldplot.tools: if isinstance(tool, PanTool): newtool = tool.clone_traits(pan_traits) newtool.component = newplot break else: newtool = PanTool(newplot) # Reconfigure the pan tool to always use the left mouse, because we will # put plot move on the right mouse button newtool.drag_button = "left" newplot.tools.append(newtool) for tool in oldplot.tools: if isinstance(tool, MoveTool): newtool = tool.clone_traits(move_traits) newtool.component = newplot break else: newtool = MoveTool(newplot, drag_button="right") newplot.tools.append(newtool) for tool in oldplot.tools: if isinstance(tool, ZoomTool): newtool = tool.clone_traits(zoom_traits) newtool.component = newplot break else: newtool = ZoomTool(newplot) newplot.tools.append(newtool) else: pz = MPPanZoom(newplot) #pz.pan.constrain = True #pz.pan.constrain_direction = "x" #pz.zoom.mode = "range" #pz.zoom.axis = "index" newplot.tools.append(MPPanZoom(newplot)) #newplot.tools.append(MTMoveTool( newplot._layout_needed = True clonetool.dest.add(newplot) newplot.invalidate_draw() newplot.request_redraw() canvas.request_redraw() return
def clone_plot(clonetool, drop_position): # A little sketchy... canvas = clonetool.component.container.component.component # Create a new Plot object oldplot = clonetool.component newplot = Plot(oldplot.data) basic_traits = ["orientation", "default_origin", "bgcolor", "border_color", "border_width", "border_visible", "draw_layer", "unified_draw", "fit_components", "fill_padding", "visible", "aspect_ratio", "title"] for attr in basic_traits: setattr(newplot, attr, getattr(oldplot, attr)) # copy the ranges dst = newplot.range2d src = oldplot.range2d #for attr in ('_low_setting', '_low_value', '_high_setting', '_high_value'): # setattr(dst, attr, getattr(src, attr)) dst._xrange.sources = copy(src._xrange.sources) dst._yrange.sources = copy(src._yrange.sources) newplot.padding = oldplot.padding newplot.bounds = oldplot.bounds[:] newplot.resizable = "" newplot.position = drop_position newplot.datasources = copy(oldplot.datasources) for name, renderers in oldplot.plots.items(): newrenderers = [] for renderer in renderers: new_r = clone_renderer(renderer) new_r.index_mapper = LinearMapper(range=newplot.index_range) new_r.value_mapper = LinearMapper(range=newplot.value_range) new_r._layout_needed = True new_r.invalidate_draw() new_r.resizable = "hv" newrenderers.append(new_r) newplot.plots[name] = newrenderers #newplot.plots = copy(oldplot.plots) for name, renderers in newplot.plots.items(): newplot.add(*renderers) newplot.index_axis.title = oldplot.index_axis.title newplot.index_axis.unified_draw = True newplot.value_axis.title = oldplot.value_axis.title newplot.value_axis.unified_draw = True # Add new tools to the new plot newplot.tools.append(AxisTool(component=newplot, range_controller=canvas.range_controller)) # Add tools to the new plot pan_traits = ["drag_button", "constrain", "constrain_key", "constrain_direction", "speed"] zoom_traits = ["tool_mode", "always_on", "axis", "enable_wheel", "drag_button", "wheel_zoom_step", "enter_zoom_key", "exit_zoom_key", "pointer", "color", "alpha", "border_color", "border_size", "disable_on_complete", "minimum_screen_delta", "max_zoom_in_factor", "max_zoom_out_factor"] move_traits = ["drag_button", "end_drag_on_leave", "cancel_keys", "capture_mouse", "modifier_key"] if not MULTITOUCH: for tool in oldplot.tools: if isinstance(tool, PanTool): newtool = tool.clone_traits(pan_traits) newtool.component = newplot break else: newtool = PanTool(newplot) # Reconfigure the pan tool to always use the left mouse, because we will # put plot move on the right mouse button newtool.drag_button = "left" newplot.tools.append(newtool) for tool in oldplot.tools: if isinstance(tool, MoveTool): newtool = tool.clone_traits(move_traits) newtool.component = newplot break else: newtool = MoveTool(newplot, drag_button="right") newplot.tools.append(newtool) for tool in oldplot.tools: if isinstance(tool, ZoomTool): newtool = tool.clone_traits(zoom_traits) newtool.component = newplot break else: newtool = ZoomTool(newplot) newplot.tools.append(newtool) else: pz = MPPanZoom(newplot) #pz.pan.constrain = True #pz.pan.constrain_direction = "x" #pz.zoom.mode = "range" #pz.zoom.axis = "index" newplot.tools.append(MPPanZoom(newplot)) #newplot.tools.append(MTMoveTool( newplot._layout_needed = True clonetool.dest.add(newplot) newplot.invalidate_draw() newplot.request_redraw() canvas.request_redraw() return
def _create_plot_component(): army_lat = np.column_stack([army['start_lat'], army['end_lat']]).reshape(-1) army_lon = np.column_stack([army['start_lon'], army['end_lon']]).reshape(-1) plot_data = ArrayPlotData( army_lon=army_lon, army_lat=army_lat, army_size=army['size'], army_color=army['direction'] * army["group"], towns_lat=towns['lat'], towns_lon=towns['lon'], towns=towns['town'], temp_lon=temperatures['lon'], temp=temperatures['temp'], temp_date=temperatures['date'], ) map_plot = Plot(plot_data) map_plot.x_grid = None map_plot.y_grid = None map_plot.x_axis.orientation = 'top' map_plot.x_axis.title = 'Longitude' map_plot.y_axis.title = 'Latitude' map_plot.title = "Minard's Map of Napoleon's Russian Campaign" map_plot._title.overlay_position = "inside top" map_plot._title.hjustify = "left" map_plot._title.vjustify = "bottom" map_plot.plot( ("army_lon", "army_lat", "army_color", "army_size"), type="cmap_segment", name="my_plot", color_mapper=viridis, border_visible=True, bgcolor="white", size_min=1.0, size_max=128.0, ) map_plot.plot( ("towns_lon", "towns_lat"), type="scatter", ) map_plot.plot( ("towns_lon", "towns_lat", "towns"), type="text", text_margin=4, h_position='right', text_offset=(4, 0), ) map_plot.plot_1d( ('temp_lon'), type='line_scatter_1d', alpha=0.5, line_style='dot', ) map_plot.index_range.high_setting = 38 map_plot.index_range.low_setting = 23 map_plot.value_range.high_setting = 56.0 map_plot.value_range.low_setting = 53.5 map_plot.tools.extend([ PanTool(map_plot), ZoomTool(map_plot), ]) temp_plot = Plot(plot_data, height=100) temp_plot.index_range = map_plot.index_range temp_plot.x_grid = None temp_plot.x_axis = None temp_plot.y_axis.orientation = 'right' temp_plot.y_axis.title = u'Temp (°Re)' temp_plot.plot( ('temp_lon', 'temp'), type='line', ) temp_plot.plot_1d( ('temp_lon'), type='line_scatter_1d', alpha=0.5, line_style='dot', ) temp_plot.plot_1d( ('temp_lon', 'temp_date'), type='textplot_1d', alpha=0.5, line_style='dot', alignment='bottom', ) temp_plot.value_range.high_setting = 5 temp_plot.value_range.low_setting = -35 container = VPlotContainer(temp_plot, map_plot) container.spacing = 0 map_plot.padding_bottom = 0 map_plot.padding_left = 70 map_plot.padding_right = 70 map_plot.padding_top = 50 temp_plot.padding_top = 0 temp_plot.padding_bottom = 15 temp_plot.padding_right = 70 temp_plot.padding_left = 70 temp_plot.height = 100 temp_plot.resizable = 'h' return container
def __init__(self, **kw): super(MLabChacoPlot, self).__init__(**kw) self.prices = get_data() x = self.prices['Date'] pd = ArrayPlotData(index = x) pd.set_data("y", self.prices["Crude Supply"]) # Create some line plots of some of the data plot = Plot(pd, bgcolor="none", padding=30, border_visible=True, overlay_border=True, use_backbuffer=False) #plot.legend.visible = True plot.plot(("index", "y"), name="Crude Price", color=(.3, .3, .8, .8)) #plot.tools.append(PanTool(plot)) plot.tools.append(PanTool(plot, constrain=True, drag_button="right", constrain_direction="x")) range_plt = plot.plots['Crude Price'][0] range_selection = RangeSelection(range_plt, left_button_selects=True) range_selection.on_trait_change(self.update_interval, 'selection') range_plt.tools.append(range_selection) range_plt.overlays.append(RangeSelectionOverlay(range_plt)) zoom = ZoomTool(component=plot, tool_mode="range", always_on=False, axis="index", max_zoom_out_factor=1.0,) plot.overlays.append(zoom) # Set the plot's bottom axis to use the Scales ticking system scale_sys = CalendarScaleSystem(fill_ratio=0.4, default_numlabels=5, default_numticks=10,) tick_gen = ScalesTickGenerator(scale=scale_sys) bottom_axis = ScalesPlotAxis(plot, orientation="bottom", tick_generator=tick_gen, label_color="white", line_color="white") # Hack to remove default axis - FIXME: how do I *replace* an axis? del(plot.underlays[-2]) plot.overlays.append(bottom_axis) # Create the mlab test mesh and get references to various parts of the # VTK pipeline f = mlab.figure(size=(700,500)) self.m = mlab.points3d(self.prices['Gasoline Supply'], self.prices['Jet Fuel Supply'], self.prices['Distillate Supply'], self.prices['Crude Supply']) # Add another glyph module to render the full set of points g2 = Glyph() g2.glyph.glyph_source.glyph_source.glyph_type = "circle" g2.glyph.glyph_source.glyph_source.filled = True g2.actor.property.opacity = 0.75 self.m.module_manager.source.add_module(g2) # Set a bunch of properties on the scene to make things look right self.m.module_manager.scalar_lut_manager.lut_mode = 'PuBuGn' self.m.glyph.mask_points.random_mode = False self.m.glyph.mask_points.on_ratio = 1 self.m.scene.isometric_view() self.m.scene.background = (.9, 0.95, 1.0) scene = mlab.gcf().scene render_window = scene.render_window renderer = scene.renderer rwi = scene.interactor plot.resizable = "" plot.bounds = [600,120] plot.padding = 25 plot.bgcolor = "white" plot.outer_position = [30,30] plot.tools.append(MoveTool(component=plot,drag_button="right")) container = OverlayPlotContainer(bgcolor = "transparent", fit_window = True) container.add(plot) # Create the Enable Window window = EnableVTKWindow(rwi, renderer, component=container, istyle_class = tvtk.InteractorStyleTrackballCamera, bgcolor = "transparent", event_passthrough = True, ) mlab.show()