예제 #1
0
    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
예제 #2
0
def create_plot():

    # Create some data
    numpts = 200
    x = sort(random(numpts))
    y = random(numpts)
    color = exp(-(x**2 + y**2))

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)
    pd.set_data("color", color)

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value", "color"),
              type="cmap_scatter",
              name="my_plot",
              color_mapper=jet,
              marker="square",
              fill_alpha=0.5,
              marker_size=6,
              outline_color="black",
              border_visible=True,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot"
    plot.padding = 50
    plot.x_grid.visible = False
    plot.y_grid.visible = False
    plot.x_axis.font = "modern 16"
    plot.y_axis.font = "modern 16"

    # Set colors
    #plot.title_color = "white"
    #for axis in plot.x_axis, plot.y_axis:
    #    axis.trait_set(title_color="white", tick_label_color="white")

    # Right now, some of the tools are a little invasive, and we need the
    # actual ColomappedScatterPlot object to give to them
    cmap_renderer = plot.plots["my_plot"][0]

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    selection = ColormappedSelectionOverlay(cmap_renderer,
                                            fade_alpha=0.35,
                                            selection_type="mask")
    cmap_renderer.overlays.append(selection)
    plot.tools.append(MoveTool(plot, drag_button="right"))
    return plot
예제 #3
0
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
예제 #4
0
def create_colorbar(colormap):
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        orientation='v',
                        resizable='',
                        height=400,
                        width=30,
                        padding=20)
    colorbar.tools.append(RangeSelection(component=colorbar))
    colorbar.overlays.append(
        RangeSelectionOverlay(component=colorbar,
                              border_color="white",
                              alpha=0.8,
                              fill_color="lightgray"))
    colorbar.tools.append(MoveTool(colorbar, drag_button="left"))
    return colorbar
예제 #5
0
 def _plot_default(self):
     # Create the data and the PlotData object
     x = linspace(-14, 14, 100)
     y = sin(x) * x**3
     plotdata = ArrayPlotData(x=x, y=y)
     # Create a Plot and associate it with the PlotData
     plot = Plot(plotdata)
     # Create a scatter plot in the Plot
     plot.plot(("x", "y"), type="scatter", color="blue")
     plot.tools.append(PanTool(plot))
     # Add our custom overlay to the plot
     overlay = CustomOverlay(plot)
     # Add the MoveTool to the overlay so it can be dragged around usin gthe
     # right mouse button.
     overlay.tools.append(MoveTool(overlay, drag_button="right"))
     plot.overlays.append(overlay)
     return plot
예제 #6
0
def main():
    from tvtk.api import tvtk
    from mayavi import mlab
    from enable.vtk_backend.vtk_window import EnableVTKWindow
    f = mlab.figure(size=(900, 850))
    m = mlab.test_mesh()
    scene = mlab.gcf().scene
    render_window = scene.render_window
    renderer = scene.renderer
    rwi = scene.interactor

    # Create the plot
    timer_controller = TimerController()
    plots = create_plot_component(timer_controller)
    specplot, timeplot, spectrogram = plots

    for i, p in enumerate(plots):
        p.resizable = ""
        p.bgcolor = "transparent"
        p.bounds = [200, 200]
        p.outer_x = 0
        p.outer_y = i * 250
        p.tools.append(MoveTool(p, drag_button="right"))
        p.tools.append(PanTool(p))
        p.tools.append(ZoomTool(p))

    spectrogram.tools[-1].tool_mode = "range"
    spectrogram.tools[-1].axis = "value"
    spectrogram.tools[-2].constrain = True
    spectrogram.tools[-2].constrain_direction = "y"

    container = OverlayPlotContainer(bgcolor="transparent", fit_window=True)
    container.add(*plots)
    container.timer_callback = timer_controller.on_timer

    window = EnableVTKWindow(
        rwi,
        renderer,
        component=container,
        istyle_class=tvtk.InteractorStyleTrackballCamera,
        bgcolor="transparent",
        event_passthrough=True,
    )

    mlab.show()
예제 #7
0
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
예제 #8
0
    def image_histogram_plot_component(self):
        xs = np.arange(0, len(self.im))
        ys = np.arange(0, len(self.im[0]))

        index = GridDataSource(xdata=xs,
                               ydata=ys,
                               sort_order=('ascending', 'ascending'))

        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=np.flipud(self.im), value_depth=1)
        reversed_grays = reverse(Greys)
        color_mapper = reversed_grays(DataRange1D(color_source))

        plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
            value_mapper=color_mapper,
        )

        #: Add overlay for zoom
        data_box_overlay = MyDataBox(
            component=plot,
            data_position=[0, 0],
            data_bounds=self.data_bounds,
        )

        move_tool = MoveTool(component=data_box_overlay)
        resize_tool = ResizeTool(component=data_box_overlay)
        data_box_overlay.tools.append(move_tool)
        data_box_overlay.tools.append(resize_tool)

        data_box_overlay.on_trait_change(self.update_position, 'position')
        data_box_overlay.on_trait_change(self.update_data_bounds, 'bounds')

        #: Add to plot
        plot.overlays.append(data_box_overlay)

        return plot
예제 #9
0
    def image_histogram_plot_component(self):
        xs = np.arange(0, len(self.im))
        ys = np.arange(0, len(self.im[0]))

        index = GridDataSource(xdata=xs,
                               ydata=ys,
                               sort_order=('ascending', 'ascending'))

        index_mapper = GridMapper(range=DataRange2D(index))

        color_source = ImageData(data=self.im, value_depth=1)
        reversed_grays = reverse(Greys)
        color_mapper = reversed_grays(DataRange1D(color_source))

        plot = CMapImagePlot(
            index=index,
            index_mapper=index_mapper,
            value=color_source,
            value_mapper=color_mapper,
            orientation='h',
            origin='top left',
        )

        self.data_box_overlay = DataBox(
            component=plot,
            data_position=[0, 0],
            data_bounds=[self.my_data_bounds, self.my_data_bounds],
        )

        move_tool = MoveTool(component=self.data_box_overlay)
        self.data_box_overlay.tools.append(move_tool)

        self.data_box_overlay.on_trait_change(self.update_my_position,
                                              'position')

        #: Add to plot
        plot.overlays.append(self.data_box_overlay)

        return plot
예제 #10
0
    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()