Exemple #1
0
 def __init__(self):
     super(StackedPlot, self).__init__()
     self.container = OverlayPlotContainer(
         bgcolor="white", use_backbuffer=True, border_visible=True, padding=50, padding_left=110, fill_padding=True
     )
     self.data = ArrayPlotData()
     self.chaco_plot = None
     self.value_mapper = None
     self.index_mapper = None
     self.x_axis = PlotAxis(
         component=self.container,
         orientation="bottom",
         title=u"Angle (2\u0398)",
         title_font=settings.axis_title_font,
         tick_label_font=settings.tick_font,
     )
     y_axis_title = "Normalized intensity (%s)" % get_value_scale_label("linear")
     self.y_axis = PlotAxis(
         component=self.container,
         orientation="left",
         title=y_axis_title,
         title_font=settings.axis_title_font,
         tick_label_font=settings.tick_font,
     )
     self.container.overlays.extend([self.x_axis, self.y_axis])
     self.container.tools.append(TraitsTool(self.container, classes=[LinePlot, PlotAxis]))
     self.colors = []
     self.last_flip_order = self.flip_order
    def _plot(self, x, y, z, scale):
        self.data_x, self.data_z, self.scale = x, z, scale
        if self.container.components:
            self.colors = map(lambda plot: plot.color, self.container.components)
            if self.last_flip_order != self.flip_order:
                self.colors.reverse()
            self.container.remove(*self.container.components)
        # Use a custom renderer so plot lines are clickable
        self.chaco_plot = Plot(self.data,
                               renderer_map={ 'line': ClickableLinePlot })
        self.chaco_plot.bgcolor = 'white'
        self.value_mapper = None
        self.index_mapper = None

        if len(self.data_x) == len(self.colors):
            colors = self.colors[:]
        else:
            colors = ['black'] * len(self.data_x)

        if self.flip_order:
            z = z[::-1]

        spacing = (z.max(axis=1) - z.min(axis=1)).min() * self.value_range
        offset = spacing * self.offset
        for i, (x_row, z_row) in enumerate(zip(x, z)):
            self.data.set_data('data_x_' + str(i), x_row)
            self.data.set_data('data_y_offset_' + str(i), z_row * self.value_range + offset * i)
            plots = self.chaco_plot.plot(('data_x_' + str(i), 'data_y_offset_' + str(i)), color=colors[i], type='line')
            plot = plots[0]
            self.container.add(plot)
            # Required for double-clicking plots
            plot.index.sort_order = 'ascending'
            plot.value.sort_order = 'ascending'

            if self.value_mapper is None:
                self.index_mapper = plot.index_mapper
                self.value_mapper = plot.value_mapper
            else:
                plot.value_mapper = self.value_mapper
                self.value_mapper.range.add(plot.value)
                plot.index_mapper = self.index_mapper
                self.index_mapper.range.add(plot.index)
        range = self.value_mapper.range
        range.high = (range.high - range.low) * self.value_range + range.low
        self.x_axis.mapper = self.index_mapper
        self.y_axis.mapper = self.value_mapper
        self.y_axis.title = 'Normalized intensity (%s)' % \
                get_value_scale_label(scale)

        #self.zoom_tool = ClickUndoZoomTool(
        #    plot, tool_mode="box", always_on=True, pointer="cross",
        #    drag_button=settings.zoom_button,
        #    undo_button=settings.undo_button,
        #)
        #plot.overlays.append(self.zoom_tool)
        #plot.tools.append(TraitsTool(plot))

        self.last_flip_order = self.flip_order
        return self.container
Exemple #3
0
 def __init__(self, callback_obj=None, *args, **kws):
     super(MplPlot, self).__init__(*args, **kws)
     self.figure = plt.figure()
     self.figure.subplots_adjust(bottom=0.05, left=0, top=1, right=0.95)
     self.ax = None
     for s in self.scale_values:
         self.z_labels[s] = 'Intensity - ' + get_value_scale_label(s, mpl=True)
     # This must be a weak reference, otherwise the entire app will
     # hang on exit.
     from weakref import proxy
     if callback_obj:
         self._callback_object = proxy(callback_obj)
     else:
         self._callback_object = lambda *args, **kw: None
Exemple #4
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
Exemple #5
0
 def _set_scale(self, scale):
     self.plot.y_axis.title = 'Intensity (%s)' % get_value_scale_label(scale)
Exemple #6
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
Exemple #7
0
 def _set_scale(self, scale):
     self.plot.y_axis.title = 'Intensity (%s)' % get_value_scale_label(scale)