From 2f41868de465b86d2fc357f7ed58ff323d58030f Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 13 May 2020 20:19:43 -0400 Subject: [PATCH] FIX: cancel pending autoscale on manually setting limits closes #17331 --- lib/matplotlib/axes/_base.py | 6 ++++++ lib/matplotlib/tests/test_axes.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index aec40541557c..30376c24280c 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3332,6 +3332,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, left, right = sorted([left, right], reverse=bool(reverse)) self._viewLim.intervalx = (left, right) + # Mark viewlims as no longer stale without triggering an autoscale. + for ax in self._shared_x_axes.get_siblings(self): + ax._stale_viewlim_x = False if auto is not None: self._autoscaleXon = bool(auto) @@ -3601,6 +3604,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, bottom, top = sorted([bottom, top], reverse=bool(reverse)) self._viewLim.intervaly = (bottom, top) + # Mark viewlims as no longer stale without triggering an autoscale. + for ax in self._shared_y_axes.get_siblings(self): + ax._stale_viewlim_y = False if auto is not None: self._autoscaleYon = bool(auto) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b7cee7b6071b..586808d95e65 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6213,6 +6213,36 @@ def test_ytickcolor_is_not_markercolor(): assert tick.tick1line.get_markeredgecolor() != 'white' +@pytest.mark.parametrize('auto', (True, False, None)) +def test_unautoscaley(auto): + fig, ax = plt.subplots() + x = np.arange(100) + y = np.linspace(-.1, .1, 100) + ax.scatter(x, y) + + post_auto = ax.get_autoscaley_on() if auto is None else auto + + ax.set_ylim((-.5, .5), auto=auto) + assert post_auto == ax.get_autoscaley_on() + fig.canvas.draw() + assert_array_equal(ax.get_ylim(), (-.5, .5)) + + +@pytest.mark.parametrize('auto', (True, False, None)) +def test_unautoscalex(auto): + fig, ax = plt.subplots() + x = np.arange(100) + y = np.linspace(-.1, .1, 100) + ax.scatter(y, x) + + post_auto = ax.get_autoscalex_on() if auto is None else auto + + ax.set_xlim((-.5, .5), auto=auto) + assert post_auto == ax.get_autoscalex_on() + fig.canvas.draw() + assert_array_equal(ax.get_xlim(), (-.5, .5)) + + @check_figures_equal(extensions=["png"]) def test_polar_interpolation_steps_variable_r(fig_test, fig_ref): l, = fig_test.add_subplot(projection="polar").plot([0, np.pi/2], [1, 2]) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy