Example #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
Example #2
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
Example #3
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
Example #4
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
class TestPlot(HasTraits):

    plot = Instance(Plot)
    plotdata = Instance(ArrayPlotData)

    # Button to reset the view to the nice original plot
    reset_view = Button(label='Reset View')
    reset_asp_ratio= Button(label='Reset Asp. Ratio')

    view = View(
                VGroup(
                    UItem('plot', editor=ComponentEditor(), resizable=True, width = .8, height = .8,),
                    HGroup(
                        Item("reset_asp_ratio", label="Reset Asp. Ratio", show_label=False),
                        Item("reset_view", label="Reset View", show_label=False),
                        ),
                    ),
                resizable=True, width=.6, height=.8,
                )

    #---------------------------------------------------------------------------
    def _plotdata_default(self):
        self.plotdata = ArrayPlotData()
        self.plotdata.set_data("x1", [0, 1, 1, 0])
        self.plotdata.set_data("y1", [0, 0, 1, 1])
        self.plotdata.set_data("x2", [1, 2, 2, 1])
        self.plotdata.set_data("y2", [0, 0, 1, 1])
        self.plotdata.set_data("x3", [0, 1, 1, 0])
        self.plotdata.set_data("y3", [1, 1, 2, 2])
        self.plotdata.set_data("x4", [1, 2, 2, 1])
        self.plotdata.set_data("y4", [1, 1, 2, 2])
        return self.plotdata

    #---------------------------------------------------------------------------
    def _plot_default(self):

        self.plot = Plot(self.plotdata)
        self.plot.plot( ("x1", "y1"), type='polygon', face_color='auto' )
        self.plot.plot( ("x2", "y2"), type='polygon', face_color='auto'  )
        self.plot.plot( ("x3", "y3"), type='polygon', face_color='auto'  )
        self.plot.plot( ("x4", "y4"), type='polygon', face_color='auto'  )
        self.plot.aspect_ratio =  1.0

        # Add Pan & ZoomTool
        zoom = ZoomTool(self.plot, tool_mode="box",always_on=True,)
        self.plot.overlays.append(zoom)
        return self.plot

    #---------------------------------------------------------------------------
    def _reset_asp_ratio_fired(self):
        x_lo = self.plot.x_axis.mapper.range.low
        x_hi = self.plot.x_axis.mapper.range.high
        y_lo = self.plot.y_axis.mapper.range.low
        y_hi = self.plot.y_axis.mapper.range.high
        self.plot.aspect_ratio = (x_hi-x_lo)/(y_hi-y_lo)
        self.plot.invalidate_and_redraw()

    #---------------------------------------------------------------------------
    def _reset_view_fired(self):
        self.plot.x_axis.mapper.range.set(low=0, high=2)
        self.plot.y_axis.mapper.range.set(low=0, high=2)
        self.plot.aspect_ratio = 1.0
        self.plot.invalidate_and_redraw()