8000 Backport PR #29411: fix #29410 Modifying Axes' position also alters t… · matplotlib/matplotlib@b365e09 · GitHub
[go: up one dir, main page]

Skip to content

Commit b365e09

Browse files
hu-xiaonanmeeseeksmachine
authored andcommitted
Backport PR #29411: fix #29410 Modifying Axes' position also alters the original Bbox object used for initialization
1 parent 7bde695 commit b365e09

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def __init__(self, fig,
648648
args = (rect,)
649649
subplotspec = None
650650
if len(args) == 1 and isinstance(args[0], mtransforms.Bbox):
651-
self._position = args[0]
651+
self._position = args[0].frozen()
652652
elif len(args) == 1 and np.iterable(args[0]):
653653
self._position = mtransforms.Bbox.from_bounds(*args[0])
654654
else:

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9580,3 +9580,14 @@ def test_bar_color_precedence():
95809580
bars = ax.bar([31, 32, 33], [4, 5, 6], color='red', facecolor='green')
95819581
for bar in bars:
95829582
assert mcolors.same_color(bar.get_facecolor(), 'green')
9583+
9584+
9585+
@check_figures_equal(extensions=['png'])
9586+
def test_axes_set_position_external_bbox_unchanged(fig_test, fig_ref):
9587+
# From #29410: Modifying Axes' position also alters the original Bbox
9588+
# object used for initialization
9589+
bbox = mtransforms.Bbox([[0.0, 0.0], [1.0, 1.0]])
9590+
ax_test = fig_test.add_axes(bbox)
9591+
ax_test.set_position([0.25, 0.25, 0.5, 0.5])
9592+
assert (bbox.x0, bbox.y0, bbox.width, bbox.height) == (0.0, 0.0, 1.0, 1.0)
9593+
ax_ref = fig_ref.add_axes([0.25, 0.25, 0.5, 0.5])

0 commit comments

Comments
 (0)
0