Beispiel #1
0
    def plotImage(self, image, plot=None):
        '''Plots a tiff image.

        |  image -- Image object
        |  plot  -- plot instance to be updated 
        |           if None, a plot instance will be created

        Returns the plot instance.
        '''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image.data)
            plot = Plot(pd, default_origin = "bottom left", padding=0)
            plot.bgcolor = 'white'
            plot.fixed_preferred_size = (100, 100)
            plot.x_axis.visible = False
            plot.y_axis.visible = False
            self.imageplot = plot

            imgPlot = plot.img_plot("imagedata", colormap=self.cmap, 
                                                    name='image')[0]
            self.imgPlot = imgPlot
            self.appendImageTools(imgPlot)
        else:
            plot.data.set_data('imagedata', image.data)
        plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0]
        plot.invalidate_and_redraw()
        return plot
Beispiel #2
0
    def plot1DCut(self, image, plot=None):
        '''Plots a 1D cut of the image.

        Currently, the 1D cut is a plot of mean intensity vs column #.

        |  image -- Image object
        |  plot  -- plot instance to be updated 
        |           if None, a plot instance will be created

        Returns the plot instance.
        '''
        if plot == None:
            pd = ArrayPlotData(y=np.array([0]), x=np.array([0]))
            plot = Plot(pd, padding=(70, 10, 0, 5))
            plot.plot(('x', 'y'), name='1D Cut', type='line', color='blue')
            plot.value_axis.title = '1D Cut'
            plot.x_axis.visible = False
            plot.bgcolor = "white"
            plot.fixed_preferred_size = (100, 30)
            plot.value_range.low = 'auto'
            plot.value_range.high = 'auto'
            plot.index_range.low = 'auto'
            plot.index_range.high = 'auto'
            self.append1DCutTools(plot)
        else:
            index = range(image.data.shape[1])
            values = image.data.mean(axis=0)
            self.setData(values, index, plot)
        plot.invalidate_and_redraw()
        return plot
Beispiel #3
0
    def _signals_plot_default(self):
        print('_signals_plot_default')
        """Create the Plot instance."""

        plot = Plot()

        plot.add(self.signals_renderer)

        x_axis = PlotAxis(component=plot,
                          mapper=self.signals_renderer.index_mapper,
                          orientation='bottom')
        # y_axis = PlotAxis(component=plot,
        #                     mapper=self.signals_renderer.value_mapper,
        #                     orientation='left')
        plot.overlays.extend([x_axis])

        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
Beispiel #4
0
    def plotHistogram(self, image, plot=None):
        '''Plots a histogram.

        |  image -- Image object
        |  plot  -- plot instance to be updated 
        |           if None, a plot instance will be created

        Returns the plot instance.
        '''
        if plot == None:
            pd = ArrayPlotData(y=np.array([0]), x=np.array([0]))
            plot = Plot(pd, padding=(70, 10, 0, 0))
            plot.plot(('x', 'y'), name='Histogram', type='bar', bar_width=1.0)
            plot.line_color = 'black'
            plot.bgcolor = "white"
            plot.fixed_preferred_size = (100, 30)
            add_default_grids(plot)
            plot.value_range.low = 'auto'
            plot.value_range.high = 'auto'
            plot.index_range.low = 'auto'
            plot.index_range.high = 'auto'
            plot.value_axis.title = "Histogram"
            self.appendHistogramTools(plot)
            
        else:
            data = np.histogram(image.data, bins=10000)
            index = np.delete(data[1], data[1].size-1)
            values = data[0]
            self.setData(values, index, plot)
        plot.invalidate_and_redraw()
        return plot
Beispiel #5
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
Beispiel #6
0
    def plotImage(self, image, title, plot):
        '''plot one image
        image:     2d ndarray or ssp matrix
        title:     string, plot title
        plot:      plot instance to be update, if None, a plot instance will be created

        return:    plot instance'''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image)
            plot = Plot(pd, default_origin = "bottom left")
            plot.title = title
            plot.bgcolor = 'white'
            if not title == 'Total Intensity':
                plot.x_axis.visible = False
                plot.y_axis.visible = False
                imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]
            # TODO: mess with color maps on else block    
            else:
                imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]

            self._appendTools(imgPlot, title)
        else:
            plot.data.set_data('imagedata', image)
            plot.title = title
        plot.aspect_ratio = float(image.shape[1]) / image.shape[0]
        plot.invalidate_draw()
        return plot
Beispiel #7
0
    def plotImage(self, image, plot=None):
        '''plot one image
        image:     Image object
        plot:      plot instance to be update, if None, a plot instance will be created
        return:    plot instance'''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image.data)
            plot = Plot(pd, default_origin = "bottom left", padding=0)
            #plot.title = image.name
            plot.bgcolor = 'white'
            plot.fixed_preferred_size = (100, 100)
            plot.x_axis.visible = False
            plot.y_axis.visible = False
            self.imageplot = plot

            # TODO: mess with color maps on else block    
            imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]
            self.imgPlot = imgPlot
            self._appendImageTools(imgPlot)
            #plot.overlays.append(MyLineDrawer(plot))
        else:
            plot.data.set_data('imagedata', image.data)
            imgPlot = plot.plots['image'][0]
            #plot.title = image.name
        plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0]
        plot.invalidate_draw()
        return plot
Beispiel #8
0
    def plotRRMap(self, ydata, title, plot=None):
        '''Plots an RR map.

        |  ydata -- y-data to be plotted
        |  title -- RR type, to be displayed on y-axis
        |  plot  -- plot instance to be updated 
        |           if None, a plot instance will be created

        Returns the plot instance.
        '''
        if plot == None:
            pd = ArrayPlotData()
            plot = Plot(pd, padding=(79, 5, 0, 0))
            self.setData(ydata, None, plot)
            plot.plot(('x', 'y'), name='rrplot', type="scatter", color='green',
                      marker="circle", marker_size=6)
            plot.value_axis.title = title
            plot.bgcolor = 'white'
            plot.aspect_ratio = 2.5
            plot.fixed_preferred_size = (100, 50)
            plot.y_axis.tick_label_formatter = lambda val:('%.2E'%val)
            plot.x_axis.visible = False
            hgrid, vgrid = add_default_grids(plot)
            self.appendRRTools(plot)
        else:
            self.setData(ydata, None, plot)
        plot.invalidate_and_redraw()
        return plot
Beispiel #9
0
    def plotHistogram(self, image, plot=None):
        if plot == None:
            pd = ArrayPlotData(y=np.array([0]), x=np.array([0]))
            plot = Plot(pd, padding=(70, 10, 0, 0))
            plot.plot(('x', 'y'), name='Histogram', type='bar', bar_width=5.0, color='auto')
            #plot.title = 'Histogram'
            plot.line_color = 'black'
            plot.bgcolor = "white"
            plot.fixed_preferred_size = (100, 30)
            add_default_grids(plot)
            plot.value_axis.title = "Histogram"
            self._appendHistogramTools(plot)
            '''
            plot.overlays.append(PlotAxis(plot, orientation='left'))
            plot.overlays.append(PlotAxis(plot, orientation='bottom'))
            '''
        else:
            data = np.histogram(image.data, bins=10000)
            index = np.delete(data[1], data[1].size-1)
            values = data[0]
            
            plot.index_range.low= np.min(index)
            plot.index_range.high = np.max(index)
            plot.value_range.low = 0
            plot.value_range.high = np.max(values)

            plot.data.set_data('x', index)
            plot.data.set_data('y', values)
        plot.request_redraw()
        return plot
Beispiel #10
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
Beispiel #11
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
 def _TracePlot_default(self):
     plot = Plot(self.TraceData, width=500, height=500, resizable='hv')
     plot.plot(('t', 'y8'),
               type='line',
               line_style='solid',
               color=0xFFFFFF,
               line_width=2,
               render_style='connectedpoints',
               name='ch0 & ch1')
     plot.bgcolor = scheme['background']
     plot.value_range.low = 0.0
     plot.x_grid = None
     plot.y_grid = None
     return plot
Beispiel #13
0
 def _create_line_plot(self):
     line_data = ArrayPlotData(frequency=np.array((0.,1.)), counts=np.array((0.,0.)), fit=np.array((0.,0.))) 
     line_plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=32)
     line_plot.plot(('frequency','counts'), style='line', color=scheme['data 1'], line_width=2)
     line_plot.bgcolor = scheme['background']
     line_plot.x_grid = None
     line_plot.y_grid = None
     line_plot.index_axis.title = 'Frequency [MHz]'
     line_plot.value_axis.title = 'Fluorescence counts'
     line_plot.value_range.low = 0.0
     line_plot.tools.append(PanTool(line_plot))
     line_plot.overlays.append(SimpleZoom(line_plot, enable_wheel=False))
     self.line_data = line_data
     self.line_plot = line_plot
Beispiel #14
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
Beispiel #15
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
Beispiel #16
0
 def plotRRMap(self, rr, rrchoice, plot=None):
     if plot == None:
         pd = ArrayPlotData(y=np.array([0]), x=np.array([0]))
         plot = Plot(pd, padding=(70, 5, 0, 0))
         self._setData(rr, plot)
         plot.plot(('x', 'y'), name='rrplot', type="scatter", color='green',
                   marker="circle", marker_size=6)
         #plot.title = 'rrplot'
         plot.value_axis.title = rrchoice
         #plot.y_axis.visible = False
         plot.bgcolor = 'white'
         plot.aspect_ratio = 2.5
         plot.fixed_preferred_size = (100, 50)
         #left, bottom = add_default_axes(plot)
         hgrid, vgrid = add_default_grids(plot)
         self._appendCMapTools(plot)
     else:
         self._setData(rr, plot)
     plot.request_redraw()
     return plot
Beispiel #17
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
Beispiel #18
0
    def _create_1D1_plot(self):
        index = 0
        plot0 = Plot(self.plotdata, padding=0)
        plot0.padding_left = 5
        plot0.padding_bottom = 5
        Container = OverlayPlotContainer(padding=50,
                                         fill_padding=True,
                                         bgcolor="lightgray",
                                         use_backbuffer=True)

        y1 = range(len(self.PCAData.batchs[0].prescores))
        points = []
        for batch in self.PCAData.batchs:
            if (self.active_scores_combobox == "Post Scores"):
                x1 = self.PCAData.batchs[index].postscores
            else:
                x1 = self.PCAData.batchs[index].prescores
            '''if (self.Shape == self.phenotypes[0]):
                    a = 1
                elif (self.Shape == self.phenotypes[1]):
                    a = batch.number
                elif (self.Shape == self.phenotypes[2]):    
                    a = batch.type
                else:
                    a = 0
                    

                if (self.Color == self.phenotypes[0]):
                    b = 0
                elif(self.Color == self.phenotypes[1]):
                    b = batch.number
                elif(self.Color == self.phenotypes[2]): 
                    b = batch.type  
                else:
                    b = 0    '''

            a = batch.type
            b = batch.number

            tmarker = shapes[a]
            bcolor = self.colors[b]

            for i in range(len(x1)):
                points.append((x1[i], y1[i]))
            plot0 = create_scatter_plot((x1, y1),
                                        marker=tmarker,
                                        color=getColor(bcolor))

            if batch.isSelected:
                plot0.alpha = 1
                plot0.alpha = 1
            else:
                plot0.fill_alpha = 0.2
                plot0.edge_alpha = 0.2

            plot0.bgcolor = "white"
            plot0.border_visible = True

            if index == 0:
                value_mapper = plot0.value_mapper
                index_mapper = plot0.index_mapper
                add_default_grids(plot0)
                add_default_axes(plot0,
                                 vtitle='PCA Indices',
                                 htitle='PCA Scores')
                plot0.index_range.tight_bounds = False
                plot0.index_range.refresh()
                plot0.value_range.tight_bounds = False
                plot0.value_range.refresh()
                plot0.tools.append(PanTool(plot0))
                zoom = ZoomTool(plot0,
                                tool_mode="box",
                                always_on=False,
                                maintain_aspect_ratio=False)
                plot0.overlays.append(zoom)
                dragzoom = DragZoom(plot0,
                                    drag_button="right",
                                    maintain_aspect_ratio=False)
                plot0.tools.append(dragzoom)

            else:
                plot0.value_mapper = value_mapper
                value_mapper.range.add(plot0.value)
                plot0.index_mapper = index_mapper
                index_mapper.range.add(plot0.index)
            if batch.isSelected:
                Container.add(plot0)
            index = index + 1

        self.RightPlot = Container
Beispiel #19
0
    def _create_1D1_plot(self):
        index = 0
        plot0 = Plot(self.plotdata, padding=0)
        plot0.padding_left = 5
        plot0.padding_bottom = 5
        Container = OverlayPlotContainer(padding = 50, fill_padding = True, bgcolor = "lightgray", use_backbuffer=True)
        
        y1 =  range(len(self.PCAData.batchs[0].prescores))
        points = []
        for batch in self.PCAData.batchs:
                if (self.active_scores_combobox == "Post Scores"):
                    x1 = self.PCAData.batchs[index].postscores
                else:
                    x1 = self.PCAData.batchs[index].prescores

                    
                if (self.Shape == self.phenotypes[0]):
                    a = 1
                elif (self.Shape == self.phenotypes[1]):
                    a = batch.number
                elif (self.Shape == self.phenotypes[2]):    
                    a = batch.type
                else:
                    a = 0
                    

                if (self.Color == self.phenotypes[0]):
                    b = 0
                elif(self.Color == self.phenotypes[1]):
                    b = batch.number
                elif(self.Color == self.phenotypes[2]): 
                    b = batch.type  
                else:
                    b = 0
                    

                tmarker = shapes[a]   
                bcolor = self.colors[b]
                
                                        
                for i in range(len(x1)):
                    points.append((x1[i],y1[i]))
                plot0 = create_scatter_plot((x1,y1), marker = tmarker, color=getColor(bcolor))
                
                if batch.isSelected:
                    plot0.alpha = 1
                else:
                    plot0.alpha = 0.2
                    
                plot0.bgcolor = "white"
                plot0.border_visible = True
                
                if index == 0:
                    value_mapper = plot0.value_mapper
                    index_mapper = plot0.index_mapper
                    add_default_grids(plot0)
                    add_default_axes(plot0, vtitle='PCA Indices', htitle='PCA Scores')
                    plot0.index_range.tight_bounds = False
                    plot0.index_range.refresh()
                    plot0.value_range.tight_bounds = False
                    plot0.value_range.refresh()
                    plot0.tools.append(PanTool(plot0))
                    zoom = ZoomTool(plot0, tool_mode="box", always_on=False,  maintain_aspect_ratio=False)
                    plot0.overlays.append(zoom)
                    dragzoom = DragZoom(plot0, drag_button="right",  maintain_aspect_ratio=False)
                    plot0.tools.append(dragzoom)
                    
                else:   
                    plot0.value_mapper = value_mapper
                    value_mapper.range.add(plot0.value)
                    plot0.index_mapper = index_mapper
                    index_mapper.range.add(plot0.index)
 
                Container.add(plot0)
                index = index +1

        self.RightPlot = Container                                          
Beispiel #20
0
    def _brain_default(self):
        plot = Plot(self.brain_data, padding=0)
        plot.width = self.brain_voxels.shape[1]
        plot.height = self.brain_voxels.shape[0]
        plot.aspect_ratio = 1.
        plot.index_axis.visible = False
        plot.value_axis.visible = False
        renderer = plot.img_plot("axial", colormap=gray)[0]
        plot.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot.bgcolor = 'pink'

        # Brain tools
        plot.tools.append(PanTool(plot, drag_button="right"))
        plot.tools.append(ZoomTool(plot))
        imgtool = ImageInspectorTool(renderer)
        renderer.tools.append(imgtool)
        overlay = ImageInspectorOverlay(component=renderer, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True)
        renderer.overlays.append(overlay)

        # Brain track cursor
        self.cursor = CursorTool2D(renderer, drag_button='left', color='red', line_width=2.0)
        #self.cursor.on_trait_change(self.update_stackedhist, 'current_index')
        self.cursor.current_positionyou = (0., 0.)
        renderer.overlays.append(self.cursor)

        # Brain colorbar
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            padding=(30, 0, 0, 0))
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Noisy brain
        plot2 = Plot(self.brain_data, padding=0)
        plot2.width = self.brain_voxels.shape[1]
        plot2.height = self.brain_voxels.shape[0]
        plot2.aspect_ratio = 1.
        plot2.index_axis.visible = False
        plot2.value_axis.visible = False
        renderer2 = plot2.img_plot("noisy_axial", colormap=gray)[0]
        plot2.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot2.bgcolor = 'pink'
        plot2.range2d = plot.range2d

        # Brain_map tools
        plot2.tools.append(PanTool(plot2, drag_button="right"))
        plot2.tools.append(ZoomTool(plot2))
        imgtool2 = ImageInspectorTool(renderer2)
        renderer2.tools.append(imgtool2)
        overlay2 = ImageInspectorOverlay(component=renderer2, image_inspector=imgtool2,
                                         bgcolor="white", border_visible=True)
        renderer2.overlays.append(overlay2)

        # Brain_map track cursor
        self.cursor2 = CursorTool2D(renderer2, drag_button='left', color='red', line_width=2.0)
        #self.cursor2.on_trait_change(self.cursor2_changed, 'current_index')
        self.cursor2.current_position = (0., 0.)
        renderer2.overlays.append(self.cursor2)

        # Brain_map colorbar
        colormap2 = plot2.color_mapper
        colorbar2 = ColorBar(index_mapper=LinearMapper(range=colormap2.range),
                             color_mapper=colormap2,
                             plot=plot2,
                             orientation='v',
                             resizable='v',
                             width=20,
                             padding=(30, 0, 0, 0))
        colorbar2.padding_top = plot2.padding_top
        colorbar2.padding_bottom = plot2.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container.add(plot)
        container.add(colorbar)
        container.bgcolor = "lightgray"

        container2 = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container2.add(plot2)
        container2.add(colorbar2)
        container2.bgcolor = "lightgray"

        Hcontainer = HPlotContainer(use_backbuffer=True)
        Hcontainer.add(container)
        Hcontainer.add(container2)
        Hcontainer.bgcolor = "lightgray"

        return Hcontainer
Beispiel #21
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
        pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = "white"
        cmap = fix(jet, (0, z.max()))
        origin = "bottom left"  # origin = 'top left' # to flip y-axis
        plot.img_plot(
            "imagedata",
            name="surface2d",
            xbounds=(np.min(x), np.max(x)),
            ybounds=(1.0, y[-1, -1]),
            colormap=cmap,
            hide_grids=True,
            interpolation="nearest",
            origin=origin,
        )
        plot.default_origin = origin
        plot.x_axis.title = u"Angle (2\u0398)"

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        plot.y_axis.tick_interval = 1.0
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot,
            tool_mode="box",
            always_on=True,
            pointer="cross",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf,
            y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(
            index_mapper=LinearMapper(range=colormap.range),
            color_mapper=colormap,
            plot=actual_plot,
            orientation="v",
            resizable="v",
            width=30,
            padding=40,
            padding_top=50,
            fill_padding=True,
        )

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font
        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(
            colorbar,
            axis="index",
            tool_mode="range",
            always_on=True,
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
        )
        pan_tool = PanToolWithHistory(
            colorbar,
            history_tool=self.colorbar_zoom_tool,
            constrain_direction="y",
            constrain=True,
            drag_button=settings.pan_button,
        )
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u"Intensity\n{:^9}".format("(" + get_value_scale_label(scale) + ")"),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        return container
Beispiel #22
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
        pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = 'white'
        cmap = fix(jet, (0, z.max()))
        origin = 'bottom left' # origin = 'top left' # to flip y-axis
        plot.img_plot("imagedata", name="surface2d",
                      xbounds=(np.min(x), np.max(x)),
                      ybounds=(1.0, y[-1,-1]),
                      colormap=cmap, hide_grids=True, interpolation='nearest',
                      origin=origin,
                      )
        plot.default_origin = origin
        plot.x_axis.title = u'Angle (2\u0398)'

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        plot.y_axis.tick_interval = 1.0
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot, tool_mode="box", always_on=True, pointer="cross",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=actual_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=40,
                        padding_top=50,
                        fill_padding=True)

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font
        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar,
                                                    axis="index",
                                                    tool_mode="range",
                                                    always_on=True,
                                                    drag_button=settings.zoom_button,
                                                    undo_button=settings.undo_button)
        pan_tool = PanToolWithHistory(colorbar,
                                      history_tool=self.colorbar_zoom_tool,
                                      constrain_direction="y", constrain=True,
                                      drag_button=settings.pan_button)
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        return container
Beispiel #23
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
     #   pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = 'white'
        cmap = fix(jet, (0, z.max()))
        plot.default_origin = 'bottom left' # origin = 'top left' # to flip y-axis

        fid = FunctionImageData(func=self._prepare_data_for_window, data_range=plot.range2d)
        pd.set_data("imagedata", fid)

        self.img_plot = plot.img_plot("imagedata", name="surface2d",
                      xbounds=(np.min(x), np.max(x)),
                      ybounds=(1.0, y[-1,-1]),
                      colormap=cmap, hide_grids=True, interpolation='nearest'
                     # origin=origin,
                      )[0]
        #plot.default_origin = origin
        
        plot.x_axis = MyPlotAxis(component=plot, orientation='bottom')
        plot.y_axis = MyPlotAxis(component=plot, orientation='left')
        plot.x_axis.title = u'Angle (2\u0398)'

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        # if <10 datasets we want to reduce down the tickmarks to multiples
        if len(y)<10:
            plot.y_axis.tick_interval = 1.0
        else:
            plot.y_axis.tick_interval = len(y)/10
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot, always_on=True, pointer="cross",
            tool_mode="range",
            axis="index",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=actual_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=40,
                        padding_top=50,
                        fill_padding=True)

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font


        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar,
                                                    axis="index",
                                                    tool_mode="range",
                                                    always_on=True,
                                                    drag_button=settings.zoom_button,
                                                   undo_button=settings.undo_button)
        pan_tool = PanToolWithHistory(colorbar,
                                      history_tool=self.colorbar_zoom_tool,
                                      constrain_direction="y", constrain=True,
                                      drag_button=settings.pan_button)
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        self.twod_plot = plot 
        return container
Beispiel #24
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()