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

Skip to content

Commit 3a0bc88

Browse files
authored
Merge pull request #28375 from joe-saronic/fix-affine-delta-transform
FIX: Made AffineDeltaTransform pass-through properly
2 parents b01462c + 0b91d8e commit 3a0bc88

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``transforms.AffineDeltaTransform`` updates correctly on axis limit changes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Before this change, transform sub-graphs with ``AffineDeltaTransform`` did not update correctly.
5+
This PR ensures that changes to the child transform are passed through correctly.

lib/matplotlib/tests/test_transforms.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,31 @@ def test_deepcopy(self):
341341
assert_array_equal(s.get_matrix(), a.get_matrix())
342342

343343

344+
class TestAffineDeltaTransform:
345+
def test_invalidate(self):
346+
before = np.array([[1.0, 4.0, 0.0],
347+
[5.0, 1.0, 0.0],
348+
[0.0, 0.0, 1.0]])
349+
after = np.array([[1.0, 3.0, 0.0],
350+
[5.0, 1.0, 0.0],
351+
[0.0, 0.0, 1.0]])
352+
353+
# Translation and skew present
354+
base = mtransforms.Affine2D.from_values(1, 5, 4, 1, 2, 3)
355+
t = mtransforms.AffineDeltaTransform(base)
356+
assert_array_equal(t.get_matrix(), before)
357+
358+
# Mess with the internal structure of `base` without invalidating
359+
# This should not affect this transform because it's a passthrough:
360+
# it's always invalid
361+
base.get_matrix()[0, 1:] = 3
362+
assert_array_equal(t.get_matrix(), after)
363+
364+
# Invalidate the base
365+
base.invalidate()
366+
assert_array_equal(t.get_matrix(), after)
367+
368+
344369
def test_non_affine_caching():
345370
class AssertingNonAffineTransform(mtransforms.Transform):
346371
"""

lib/matplotlib/transforms.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,9 +2721,12 @@ class AffineDeltaTransform(Affine2DBase):
27212721
This class is experimental as of 3.3, and the API may change.
27222722
"""
27232723

2724+
pass_through = True
2725+
27242726
def __init__(self, transform, **kwargs):
27252727
super().__init__(**kwargs)
27262728
self._base_transform = transform
2729+
self.set_children(transform)
27272730

27282731
__str__ = _make_str_method("_base_transform")
27292732

0 commit comments

Comments
 (0)