Skip to content

Commit a046ee3

Browse files
authored
Merge pull request #25126 from tacaswell/fix_lines_change_scale
FIX: fully invalidate TransformWrapper parents before swapping
2 parents 1367ea5 + 58cadad commit a046ee3

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
@@ -1732,6 +1732,7 @@ def set(self, child):
17321732
dimensions as the current child.
17331733
"""
17341734
if hasattr(self, "_child"): # Absent during init.
1735+
self.invalidate()
17351736
new_dims = (child.input_dims, child.output_dims)
17361737
old_dims = (self._child.input_dims, self._child.output_dims)
17371738
if new_dims != old_dims:

0 commit comments

Comments
 (0)