Пример #1
0
def _create_plot_component():

    # Create some RGBA image data
    image = zeros((200,400,4), dtype=uint8)
    image[:,0:40,0] += 255     # Vertical red stripe
    image[0:25,:,1] += 255     # Horizontal green stripe; also yellow square
    image[-80:,-160:,2] += 255 # Blue square
    image[:,:,3] = 255

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", image)

    # Create the plot
    plot = Plot(pd, default_origin="top left")
    plot.x_axis.orientation = "top"
    img_plot = plot.img_plot("imagedata")[0]

    # Tweak some of the plot properties
    plot.bgcolor = "white"

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    plot.overlays.append(ZoomTool(component=plot,
                                    tool_mode="box", always_on=False))

    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    plot.overlays.append(ImageInspectorOverlay(component=img_plot,
                                               image_inspector=imgtool))
    return plot
Пример #2
0
    def _create_plot_component(self):
        pd = self.pd

    # Create the plot
        plot = Plot(pd, default_origin="top left",orientation="h")
        shape = pd.get_data('imagedata').shape
        plot.aspect_ratio = float(shape[1]) / shape[0]
        plot.x_axis.orientation = "top"
        #plot.y_axis.orientation = "top"
        #img_plot = plot.img_plot("imagedata",colormap = jet)[0]
        img_plot = plot.img_plot("imagedata",name = 'image', colormap = jet)[0]
        
    # Tweak some of the plot properties
        #plot.bgcolor = "white"
        plot.bgcolor = bg_color
        
    # Attach some tools to the plot
        plot.tools.append(PanTool(plot,constrain_key="shift", drag_button = 'right'))
        printer = DataPrinter(component=plot, process = self.process_selection)
        plot.tools.append(printer)
        plot.overlays.append(ZoomTool(component=plot, 
                                  tool_mode="box", always_on=False))
        #plot.title = 'Default image'
        
        imgtool = ImageInspectorTool(img_plot)
        img_plot.tools.append(imgtool)
        plot.overlays.append(ImageInspectorOverlay(component=img_plot, 
                                               image_inspector=imgtool))
        return plot
Пример #3
0
    def _image_plot_default(self):
        plot = Plot(self.image_data, default_origin="top left")
        #plot.x_axis.orientation = "top"
        img_plot = plot.img_plot("image_data")[0]

        plot.bgcolor = "black"
        return plot
Пример #4
0
    def _vr_image_plot_default(self):
        plot = Plot(self.vr_image_data, default_origin="top left",
                    size=(512,512))
        plot.aspect_ratio = 1.0
        #plot.x_axis.orientation = "top"
        img_plot = plot.img_plot("vr_image_data")[0]

        plot.bgcolor = "black"
        return plot
 def _phi_plot_default(self):
     data = ArrayPlotData(h=self.h_range, phi=self.phi_sample)
     p = Plot(data)
     p.plot(('h', 'phi'), type='line', name='phi', color='slateblue', line_width=2.7)
     p.x_axis.title = 'h'
     p.y_axis.title = 'Phi[h]'
     p.x_grid.line_color = p.y_grid.line_color = 'slategray'
     p.bgcolor = 'khaki'
     p.title = 'Nonlinearity'
     return p
 def _units_plot_default(self):
     N = min([self.N_CA, DISP_UNITS])
     data = ArrayPlotData(i=numpy.arange(N), r=self.r[:N], i_aff=self.i_aff[:N])
     p = Plot(data)
     p.plot(('i', 'r', 'i_aff'), type='cmap_scatter', color_mapper=hot, 
         marker='circle', marker_size=3, line_width=0)
     p.title = 'Place Cell Output'
     p.x_axis.title = 'Output Units'
     p.y_axis.title = 'Rate / Iaff'
     p.value_range.set_bounds(0.0, 1.0)
     p.x_grid.visible = p.y_grid.visible = False
     p.bgcolor = 'slategray'
     return p
Пример #7
0
    def _create_plot_component(self):

        # Create the plot
        pd = self.pd
        plot = Plot(pd, default_origin="top left", orientation="h")
        plot.x_axis.orientation = "top"
        plot.padding = 20
        #plot.y_axis.orientation = "top"

        # Tweak some of the plot properties
        #plot.bgcolor = "white"
        plot.bgcolor = bg_color

        # Attach some tools to the plot

        # plot.tools.append(PanTool(plot,constrain_key="shift", drag_button = 'right'))
        printer = DataPrinter(component=plot, process=self.process_selection)
        plot.tools.append(printer)
        plot.overlays.append(
            ZoomTool(component=plot, tool_mode="box", always_on=False))
        return plot
 def _field_plots_default(self):
     zero = numpy.array([0], 'd')
     data = ArrayPlotData(t=zero, h_rec=zero, h_aff=zero, h_sum=zero)
     p = Plot(data)
     p.plot(('t', 'h_aff'), name='Afferent', type='line', line_width=1, color='royalblue')
     p.plot(('t', 'h_rec'), name='Recurrent', type='line', line_width=1, color='tomato')
     p.plot(('t', 'h_sum'), name='Total', type='line', line_width=1, color='sienna')
     
     p.legend.visible = True
     p.legend.border_visible = False
     p.legend.align = 'ur'
     p.legend.bgcolor = (0.8, 0.8, 1.0, 0.4)
     p.legend.border_padding = 6
     p.legend.labels = ['Afferent', 'Recurrent', 'Total']
     
     p.y_grid.visible = p.x_grid.visible = False
     p.title = 'Synaptic Fields'
     p.x_axis.title = 'Time (s)'
     p.y_axis.title = 'Field Strength'
     p.bgcolor = 'mintcream'
     return p
    def _plot_default(self):
        self._pd = ArrayPlotData()
        self._pd.set_data("imagedata", self._image)

        plot = Plot(self._pd, default_origin="top left")
        plot.x_axis.orientation = "top"
        img_plot = plot.img_plot("imagedata")[0]

        plot.bgcolor = "white"

        # Tweak some of the plot properties
        plot.title = "Click to add points, press Enter to clear selection"
        plot.padding = 50
        plot.line_width = 1

        # Attach some tools to the plot
        pan = PanTool(plot, drag_button="right", constrain_key="shift")
        plot.tools.append(pan)
        zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        return plot
Пример #10
0
    def _plot_default(self):
        self._pd = ArrayPlotData()
        self._pd.set_data("imagedata", self._image)

        plot = Plot(self._pd, default_origin="top left")
        plot.x_axis.orientation = "top"
        img_plot = plot.img_plot("imagedata")[0]

        plot.bgcolor = "white"

        # Tweak some of the plot properties
        plot.title = "Click to add points, press Enter to clear selection"
        plot.padding = 50
        plot.line_width = 1

        # Attach some tools to the plot
        pan = PanTool(plot, drag_button="right", constrain_key="shift")
        plot.tools.append(pan)
        zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        return plot
Пример #11
0
    def add_plot(self, signal, sweep_point=None):
##        waveform = signal.get_waveform()
##        x = waveform.get_x()[-1][0].tolist()
##        y = np.real(waveform.get_y()[0].tolist())

        if sweep_point is None:
            sweep_point = signal.get_circuit()._sweep_set._points[0]

        trace = Trace(signal, self, self._next_color(), sweep_point)

        x_name = trace.index_label
        y_name = trace.label

        x = trace.get_indices()
        y = trace.get_values()
        if type(y[0]) == complex:
            y = [value.real for value in y]
        #print x_name, len(x)
        #print y_name, len(y)
        #print x
        #print y

        if self.firstplot:
            self.plotdata = ArrayPlotData()
            self.plotdata.set_data(x_name, x)
            self.plotdata.set_data(y_name, y)

            plot = Plot(self.plotdata)
            plot.padding = 1

            plot.bgcolor = "white"
            plot.border_visible = True
            add_default_grids(plot)
            add_default_axes(plot)

            plot.tools.append(PanTool(plot))

            # The ZoomTool tool is stateful and allows drawing a zoom
            # box to select a zoom region.
            zoom = CustomZoomTool(plot)
            plot.overlays.append(zoom)

            # The DragZoom tool just zooms in and out as the user drags
            # the mouse vertically.
            dragzoom = DragZoom(plot, drag_button="right")
            plot.tools.append(dragzoom)

            #~ # Add a legend in the upper right corner, and make it relocatable
            #~ self.legend = Legend(component=plot, padding=10, align="ur")
            #~ self.legend.tools.append(LegendTool(self.legend, drag_button="right"))
            #~ plot.overlays.append(self.legend)

            #~ self.legend.plots = {}

            self.firstplot = False

            self.container.add(plot)

            self.plot = plot

        else:
            self.plotdata.set_data(x_name, x)
            self.plotdata.set_data(y_name, y)

        #self.plot.plot(self.plotdata.list_data())
        pl = self.plot.plot( (x_name, y_name), name=trace.label, type="line",
            color=trace.color, line_style=trace.line_style,
            line_width=trace.line_width, marker=trace.marker,
            marker_size=trace.marker_size, marker_color=trace.marker_color)

        self.legend.plots[trace.label] = pl

        self.Refresh()
Пример #12
0
def _create_plot_component(file_name):
    # Create a scalar field to colormap
    z = load(file_name)
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)
    
    # Create the plot
    plot = Plot(pd)
    plot.bgcolor = 'gray'
    
    img_plot = plot.img_plot("imagedata",
                             name='my_plot', 
                             colormap=jet,
                             hide_grids=True)[0]
    #cont_plot=plot.contour_plot('imagedata', type='line', name='countour')
    # Tweak some of the plot properties
    #plot.title = file_name
    plot.padding = 40
    plot.padding_right=20
    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    #plot.tools.append(TraitsTool(plot))
    zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
    img_plot.overlays.append(zoom)
    #plot.y_axis.tick_label_formatter = lambda x: "%.3e" % x
    #plot.x_axis.tick_label_formatter = lambda x: "%.3e" % x
    #plot.tools.append(SaveTool(plot))
    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    my_plot = img_plot#plot.plots["my_plot"][0]
    colormap = my_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=my_plot,
                        orientation='v',
                        resizable='v',
                        width=25,
                        padding=0)
    colorbar.origin = 'bottom left'
    #colorbar._axis.tick_label_formatter = lambda x: '%.0e'%(x*10e6) + u' [\u00b5' + 'Watt]'
    colorbar._axis.tick_label_formatter = lambda x: ('%.0e'%(x*1e6))
    colorbar._axis.orientation = 'right'
    colorbar._axis.title = u'Intensity [\u00b5W]'
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom
    colorbar.padding_right = 100
    # create a range selection for the colorbar
    range_selection = RangeSelection(component=colorbar)
    colorbar.tools.append(range_selection)
    colorbar.overlays.append(RangeSelectionOverlay(component=colorbar,
                                                   border_color="white",
                                                   alpha=0.5,
                                                   fill_color="lightgray"))
    
    range_selection.listeners.append(my_plot)
    
    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool))
    # we also want to the range selection to inform the cmap plot of
    # the selection, so set that up as well

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer = True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "white"
    container.tools.append(SaveTool(container))
    container.tools.append(TraitsTool(container))
    #my_plot.set_value_selection((-1.3, 6.9))
    return container    
Пример #13
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()