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
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
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