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

Skip to content

Commit 58cadad

Browse files
committed
FIX: fully invalidate TransformWrapper parents before swapping
The issue is that TransformedPath only regenerates its cache for changes to the non-affine part of the transform. When TransformWrapper for tranScale changes from log -> linear the non-affine part of the log transform is still cached, but when the transforms are invalidated after switching to linear the invalidation only reports changing the affine part so the cache in TransformedPath escapes being updated (nulled out in this case) and when we re-draw with linear is drawing the line off screen (or at least clipped). This change invalidates all of the parents before changing the internals of TransformWrapper before we switch it which will cause the non-affine part to be correctly recomputed the next time we need it. closes #25124
1 parent f3938be commit 58cadad

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)