Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83507dc

Browse files
authored
Merge pull request #9855 from jklymak/enh-update-aspect
ENH: make ax.get_position apply aspect
2 parents fb84253 + d260cca commit 83507dc

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
`.Axes.get_position` now returns actual position if aspect changed
2+
------------------------------------------------------------------
3+
4+
`.Axes.get_position` used to return the original position unless a
5+
draw had been triggered or `.Axes.apply_aspect` had been called, even
6+
if the kwarg *original* was set to *False*. Now `.Axes.apply_aspect`
7+
is called so ``ax.get_position()`` will return the new modified position.
8+
To get the old behaviour, ``ax.get_position(original=True)``.

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ def get_position(self, original=False):
848848
if original:
849849
return self._originalPosition.frozen()
850850
else:
851+
self.apply_aspect()
851852
return self._position.frozen()
852853

853854
def set_position(self, pos, which='both'):

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
12861286

12871287
# transform each of the axes in parents using the new transform
12881288
for ax in parents:
1289-
new_posn = shrinking_trans.transform(ax.get_position())
1289+
new_posn = shrinking_trans.transform(ax.get_position(original=True))
12901290
new_posn = mtransforms.Bbox(new_posn)
12911291
ax._set_position(new_posn)
12921292
if parent_anchor is not False:

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import matplotlib.markers as mmarkers
2323
import matplotlib.patches as mpatches
2424
import matplotlib.colors as mcolors
25-
from numpy.testing import assert_allclose, assert_array_equal
25+
from numpy.testing import (
26+
assert_allclose, assert_array_equal, assert_array_almost_equal)
2627
from matplotlib.cbook import (
2728
IgnoredKeywordWarning, MatplotlibDeprecationWarning)
2829

@@ -4940,6 +4941,12 @@ def test_square_plot():
49404941
xlim, ylim = ax.get_xlim(), ax.get_ylim()
49414942
assert np.diff(xlim) == np.diff(ylim)
49424943
assert ax.get_aspect() == 'equal'
4944+
assert_array_almost_equal(
4945+
ax.get_position(original=True).extents,
4946+
np.array((0.125, 0.1, 0.9, 0.9)))
4947+
assert_array_almost_equal(
4948+
ax.get_position(original=False).extents,
4949+
np.array((0.2125, 0.1, 0.8125, 0.9)))
49434950

49444951

49454952
def test_no_None():

0 commit comments

Comments
 (0)