From 6b72ae651395f6652ac39c55497380185f9670c2 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 4 Sep 2016 21:20:05 +0100 Subject: [PATCH 1/2] Make sure that autoscale respect tight closes #6968 --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 0feb87e757d1..202b558947f5 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2198,7 +2198,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True): else: _tight = self._tight = bool(tight) - if self._xmargin or self._ymargin: + if (self._xmargin or self._ymargin) and not _tight: margins = { 'top': True, 'bottom': True, From 3c3ca8828dc92dd0a38746e7b1dcdf7d897afe58 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Sun, 4 Sep 2016 21:54:51 +0100 Subject: [PATCH 2/2] Add test for tight=True in autoscale --- lib/matplotlib/tests/test_axes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 3d41e3c27422..c9600dc5a6db 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -166,6 +166,16 @@ def test_autoscale_tiny_range(): ax[i].plot([0, 1], [1, 1 + y1]) +@cleanup +def test_autoscale_tight(): + fig, ax = plt.subplots(1, 1) + ax.plot([1, 2, 3, 4]) + ax.autoscale(enable=True, axis='x', tight=False) + ax.autoscale(enable=True, axis='y', tight=True) + assert_allclose(ax.get_xlim(), (-0.15, 3.15)) + assert_allclose(ax.get_ylim(), (1.0, 4.0)) + + @image_comparison(baseline_images=['offset_points'], remove_text=True) def test_basic_annotate():