Skip to content

Commit 7fcb063

Browse files
authored
fix matplotlib#29410 Modifying Axes' position also alters the original Bbox object used for initialization (matplotlib#29411)
* fix matplotlib#29410 * Update test_axes_set_position_external_bbox_unchanged to use figure comparison
1 parent ca8079b commit 7fcb063

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/axes/_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def __init__(self, fig,
641641
args = (rect,)
642642
subplotspec = None
643643
if len(args) == 1 and isinstance(args[0], mtransforms.Bbox):
644-
self._position = args[0]
644+
self._position = args[0].frozen()
645645
elif len(args) == 1 and np.iterable(args[0]):
646646
self._position = mtransforms.Bbox.from_bounds(*args[0])
647647
else:

lib/matplotlib/tests/test_axes.py

+11
Original file line numberDiff line numberDiff line change
@@ -9610,3 +9610,14 @@ def test_bar_color_precedence():
96109610
bars = ax.bar([31, 32, 33], [4, 5, 6], color='red', facecolor='green')
96119611
for bar in bars:
96129612
assert mcolors.same_color(bar.get_facecolor(), 'green')
9613+
9614+
9615+
@check_figures_equal(extensions=['png'])
9616+
def test_axes_set_position_external_bbox_unchanged(fig_test, fig_ref):
9617+
# From #29410: Modifying Axes' position also alters the original Bbox
9618+
# object used for initialization
9619+
bbox = mtransforms.Bbox([[0.0, 0.0], [1.0, 1.0]])
9620+
ax_test = fig_test.add_axes(bbox)
9621+
ax_test.set_position([0.25, 0.25, 0.5, 0.5])
9622+
assert (bbox.x0, bbox.y0, bbox.width, bbox.height) == (0.0, 0.0, 1.0, 1.0)
9623+
ax_ref = fig_ref.add_axes([0.25, 0.25, 0.5, 0.5])

0 commit comments

Comments
 (0)