def test_plot_limits_are_not_changed_when_plotting_fit_lines_autoscale_false( self): fig, canvas, ws = self._create_and_plot_matrix_workspace() ax = fig.get_axes()[0] full_ax_limits = ax.axis() # zoom in x2 based on the central x and y values and recapture limits # note, zoom turns autoscale off zoom(ax, 0.5 * (full_ax_limits[0] + full_ax_limits[1]), 0.5 * (full_ax_limits[2] + full_ax_limits[3]), 2) ax_limits = ax.axis() canvas.draw() widget = self._create_widget(canvas=canvas) fit_ws_name = "fit_ws" # create fit workspace containing 3 spectra (data\calc\diff) CreateWorkspace(OutputWorkspace=fit_ws_name, DataX=[ax_limits[0], ax_limits[1]], DataY=[1] * 6, NSpec=3, Distribution=False) widget.fitting_done_slot(fit_ws_name) self.assertEqual(ax_limits, fig.get_axes()[0].axis()) # user picks x range bigger than current zoom (but still within ws data range). Plot limits still don't change CreateWorkspace(OutputWorkspace=fit_ws_name, DataX=[full_ax_limits[0], full_ax_limits[1]], DataY=[1] * 6, NSpec=3, Distribution=False) widget.fitting_done_slot(fit_ws_name) self.assertEqual(ax_limits, fig.get_axes()[0].axis())
def test_zoom_in_from_outside_zoom_limit(self): """ Manually set the axis range so it is outside of the zoom out limit, and make sure it's possible to zoom in. """ fig, ax = plt.subplots() ax.plot([0, 1, 2], [1e10, -1e10, 1e10]) # Set axis limits outside of the maximum zoom out range. axis_max = ZOOM_LIMIT * 2.0 axis_min = ZOOM_LIMIT * -2.0 ax.set_xlim([axis_min, axis_max]) ax.set_ylim([axis_min, axis_max]) # Attempt to zoom in. zoom_point = [0, 0] zoom_factor = 1.05 zoom(ax, *zoom_point, zoom_factor) # Check that we were able to zoom in. x_min, x_max = ax.get_xlim() y_min, y_max = ax.get_ylim() self.assertTrue(x_min > axis_min) self.assertTrue(x_max < axis_max) self.assertTrue(y_min > axis_min) self.assertTrue(y_max < axis_max)
def on_scroll(self, event): """Respond to scroll events: zoom in/out""" self.canvas.toolbar.push_current() if not getattr(event, 'inaxes', None) or isinstance(event.inaxes, Axes3D): return zoom_factor = 1.05 + abs(event.step)/6 if event.button == 'up': # zoom in zoom(event.inaxes, event.xdata, event.ydata, factor=zoom_factor) elif event.button == 'down': # zoom out zoom(event.inaxes, event.xdata, event.ydata, factor=1/zoom_factor) event.canvas.draw()
def test_zoom_sets_correct_axis_limits(self): fig, ax = plt.subplots() ax.plot([0, 1, 2], [6, 4, 6]) zoom_point = [2, 6] factor = 1 / 1.1 # = 0.909090... xlims, ylims = zoom(ax, *zoom_point, factor=factor) np_testing.assert_almost_equal([-0.31, 2.11], xlims) np_testing.assert_almost_equal([3.69, 6.11], ylims)