def set_figure_zoom_to_display_all(self): axes = self.canvas.figure.get_axes() if axes: for ax in axes: # We check for axes type below as a pseudo check for an axes being # a colorbar. this is based on the same check in # FigureManagerADSObserver.deleteHandle. if type(ax) is not Axes: if ax.lines: # Relim causes issues with colour plots, which have no lines. ax.relim() elif isinstance(ax, Axes3D): if hasattr(ax, 'original_data_surface'): ax.collections[0]._vec = copy.deepcopy( ax.original_data_surface) elif hasattr(ax, 'original_data_wireframe'): ax.collections[0].set_segments( copy.deepcopy(ax.original_data_wireframe)) else: ax.view_init() elif ax.images: axesfunctions.update_colorplot_datalimits( ax, ax.images) continue ax.autoscale() self.canvas.draw()
def _toggle_normalization(self, selected_ax): if figure_type(self.canvas.figure) == FigureType.Image and len(self.canvas.figure.get_axes()) > 1: axes = datafunctions.get_axes_from_figure(self.canvas.figure) else: axes = [selected_ax] for ax in axes: waterfall = isinstance(ax, MantidAxes) and ax.is_waterfall() if waterfall: x, y = ax.waterfall_x_offset, ax.waterfall_y_offset has_fill = ax.waterfall_has_fill() if has_fill: line_colour_fill = datafunctions.waterfall_fill_is_line_colour(ax) if line_colour_fill: fill_colour = None else: fill_colour = datafunctions.get_waterfall_fills(ax)[0].get_facecolor() ax.update_waterfall(0, 0) # The colorbar can get screwed up with ragged workspaces and log scales as they go # through the normalisation toggle. # Set it to Linear and change it back after if necessary, since there's no reason # to duplicate the handling. colorbar_log = False if ax.images: colorbar_log = isinstance(ax.images[-1].norm, LogNorm) if colorbar_log: self._change_colorbar_axes(Normalize) self._change_plot_normalization(ax) if ax.lines: # Relim causes issues with colour plots, which have no lines. ax.relim() ax.autoscale() if ax.images: # Colour bar limits are wrong if workspace is ragged. Set them manually. colorbar_min = np.nanmin(ax.images[-1].get_array()) colorbar_max = np.nanmax(ax.images[-1].get_array()) for image in ax.images: image.set_clim(colorbar_min, colorbar_max) # Update the colorbar label cb = image.colorbar if cb: datafunctions.add_colorbar_label(cb, ax.get_figure().axes) if colorbar_log: # If it had a log scaled colorbar before, put it back. self._change_colorbar_axes(LogNorm) axesfunctions.update_colorplot_datalimits(ax, ax.images) datafunctions.set_initial_dimensions(ax) if waterfall: ax.update_waterfall(x, y) if has_fill: ax.set_waterfall_fill(True, fill_colour) self.canvas.draw()
def _do_update_colorplot_datalimits(self, color_func): fig, ax = plt.subplots() mesh = color_func(ax, self.ws2d_histo) ax.set_xlim(0.01, 0.05) ax.set_ylim(-0.05, 0.05) funcs.update_colorplot_datalimits(ax, mesh) self.assertAlmostEqual(10.0, ax.get_xlim()[0]) from distutils.version import LooseVersion # different results with 1.5.3 and 2.1.1 if color_func.__name__ != 'imshow' and LooseVersion(matplotlib.__version__) < LooseVersion("2"): self.assertAlmostEqual(100.0, ax.get_xlim()[1]) else: self.assertAlmostEqual(30.0, ax.get_xlim()[1]) self.assertAlmostEqual(4.0, ax.get_ylim()[0]) self.assertAlmostEqual(8.0, ax.get_ylim()[1])
def test_update_colorplot_datalimits_for_both_axis(self): """Check that the function is only operating on y-axis""" ax_mock = mock.MagicMock() funcs.update_colorplot_datalimits(ax_mock, ax_mock.images, 'both') ax_mock.update_datalim.assert_called_once_with(mock.ANY, True, True) ax_mock.autoscale.assert_called_once_with(axis='both')
def _apply_properties_to_axes(self, ax): """Apply current properties to given set of axes""" self.set_ax_canvas_color(ax, self.current_view_props['canvas_color']) if not isinstance(ax, Axes3D): if self.current_view_props['minor_ticks']: ax.minorticks_on() else: ax.minorticks_off() ax.show_minor_gridlines = self.current_view_props[ 'minor_gridlines'] # If the grid is enabled update it if ax.show_minor_gridlines: if ax.xaxis._major_tick_kw[ 'gridOn'] and ax.yaxis._major_tick_kw['gridOn']: ax.grid(True, which='minor') elif ax.xaxis._major_tick_kw['gridOn']: ax.grid(True, axis='x', which='minor') elif ax.yaxis._major_tick_kw['gridOn']: ax.grid(True, axis='y', which='minor') else: ax.grid(False, which='minor') if "xlabel" in self.current_view_props: ax.set_xlabel(self.current_view_props['xlabel']) ax.set_xscale(self.current_view_props['xscale']) if self.current_view_props['xautoscale']: if ax.images: axesfunctions.update_colorplot_datalimits(ax, ax.images, axis='x') else: ax.autoscale(True, axis="x") else: if isinstance(ax, Axes3D): ax.set_xlim3d(self.current_view_props['xlim']) else: ax.set_xlim(self.current_view_props['xlim']) if "ylabel" in self.current_view_props: ax.set_ylabel(self.current_view_props['ylabel']) ax.set_yscale(self.current_view_props['yscale']) if self.current_view_props['yautoscale']: if ax.images: axesfunctions.update_colorplot_datalimits(ax, ax.images, axis='y') else: ax.autoscale(True, axis="y") else: if isinstance(ax, Axes3D): ax.set_ylim3d(self.current_view_props['ylim']) else: ax.set_ylim(self.current_view_props['ylim']) if isinstance(ax, Axes3D) and "zlabel" in self.current_view_props: ax.set_zlabel(self.current_view_props['zlabel']) ax.set_zscale(self.current_view_props['zscale']) if self.current_view_props['zautoscale']: ax.autoscale(True, axis="z") else: ax.set_zlim3d(self.current_view_props['zlim'])