8000 Backport PR #25126: FIX: fully invalidate TransformWrapper parents be… · matplotlib/matplotlib@ba1b912 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba1b912

Browse files
anntzermeeseeksmachine
authored andcommitted
Backport PR #25126: FIX: fully invalidate TransformWrapper parents before swapping
1 parent d247979 commit ba1b912

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import matplotlib.patches as mpatches
1111
import matplotlib.transforms as mtransforms
1212
from matplotlib.path import Path
13-
from matplotlib.testing.decorators import image_comparison
13+
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1414

1515

1616
def test_non_affine_caching():
@@ -730,3 +730,17 @@ def test_transformwrapper():
730730
r"The input and output dims of the new child \(1, 1\) "
731731
r"do not match those of current child \(2, 2\)")):
732732
t.set(scale.LogTransform(10))
733+
734+
735+@check_figures_equal(extensions=["png"])
736+
def test_scale_swapping(fig_test, fig_ref):
737+
np.random.seed(19680801)
738+
samples = np.random.normal(size=10)
739+
x = np.linspace(-5, 5, 10)
740+
741+
for fig, log_state in zip([fig_test, fig_ref], [True, False]):
742+
ax = fig.subplots()
743+
ax.hist(samples, log=log_state, density=True)
744+
ax.plot(x, np.exp(-(x**2) / 2) / np.sqrt(2 * np.pi))
745+
fig.canvas.draw()
746+
ax.set_yscale('linear')

lib/matplotlib/transforms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ def set(self, child):
17191719
dimensions as the current child.
17201720
"""
17211721
if hasattr(self, "_child"): # Absent during init.
1722+
self.invalidate()
17221723
new_dims = (child.input_dims, child.output_dims)
17231724
old_dims = (self._child.input_dims, self._child.output_dims)
17241725
if new_dims != old_dims:

0 commit comments

Comments
 (0)
0