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

Skip to content

Commit 2dfd5b0

Browse files
committed
Add ability to compose transforms of any dimension
1 parent 7cf95f1 commit 2dfd5b0

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def test_str_transform():
853853
BlendedAffine(
854854
IdentityTransform(),
855855
IdentityTransform())),
856-
CompositeAffine2D(
856+
CompositeAffine(
857857
Affine2D().scale(1.0),
858858
Affine2D().scale(1.0))),
859859
PolarTransform(
@@ -876,7 +876,7 @@ def test_str_transform():
876876
(0.5, 0.5),
877877
TransformedBbox(
878878
Bbox(x0=0.0, y0=0.0, x1=6.283185307179586, y1=1.0),
879-
CompositeAffine2D(
879+
CompositeAffine(
880880
Affine2D().scale(1.0),
881881
Affine2D().scale(1.0))),
882882
LockableBbox(

lib/matplotlib/transforms.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ def _invalidate_internal(self, level, invalidating_node):
24662466
super()._invalidate_internal(level, invalidating_node)
24672467

24682468
def __eq__(self, other):
2469-
if isinstance(other, (CompositeGenericTransform, CompositeAffine2D)):
2469+
if isinstance(other, (CompositeGenericTransform, CompositeAffine)):
24702470
return self is other or (self._a == other._a
24712471
and self._b == other._b)
24722472
else:
@@ -2526,7 +2526,7 @@ def inverted(self):
25262526
self._b.inverted(), self._a.inverted())
25272527

25282528

2529-
class CompositeAffine2D(Affine2DBase):
2529+
class CompositeAffine(AffineImmutable):
25302530
"""
25312531
A composite transform formed by applying transform *a* then transform *b*.
25322532
@@ -2536,7 +2536,7 @@ class CompositeAffine2D(Affine2DBase):
25362536
def __init__(self, a, b, **kwargs):
25372537
"""
25382538
Create a new composite transform that is the result of
2539-
applying `Affine2DBase` *a* then `Affine2DBase` *b*.
2539+
applying `AffineImmutable` *a* then `AffineImmutable` *b*.
25402540
25412541
You will generally not call this constructor directly but write ``a +
25422542
b`` instead, which will automatically choose the best kind of composite
@@ -2547,10 +2547,8 @@ def __init__(self, a, b, **kwargs):
25472547
if a.output_dims != b.input_dims:
25482548
raise ValueError("The output dimension of 'a' must be equal to "
25492549
"the input dimensions of 'b'")
2550-
self.input_dims = a.input_dims
2551-
self.output_dims = b.output_dims
2550+
super().__init__(dims=a.output_dims, **kwargs)
25522551

2553-
super().__init__(**kwargs)
25542552
self._a = a
25552553
self._b = b
25562554
self.set_children(a, b)
@@ -2579,6 +2577,11 @@ def get_matrix(self):
25792577
return self._mtx
25802578

25812579

2580+
@_api.deprecated("3.9", alternative="CompositeAffine")
2581+
class CompositeAffine2D(CompositeAffine):
2582+
pass
2583+
2584+
25822585
def composite_transform_factory(a, b):
25832586
"""
25842587
Create a new composite transform that is the result of applying
@@ -2602,7 +2605,7 @@ def composite_transform_factory(a, b):
26022605
elif isinstance(b, IdentityTransform):
26032606
return a
26042607
elif isinstance(a, Affine2D) and isinstance(b, Affine2D):
2605-
return CompositeAffine2D(a, b)
2608+
return CompositeAffine(a, b)
26062609
return CompositeGenericTransform(a, b)
26072610

26082611

lib/matplotlib/transforms.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,14 @@ class CompositeGenericTransform(Transform):
282282
pass_through: bool
283283
def __init__(self, a: Transform, b: Transform, **kwargs) -> None: ...
284284

285-
class CompositeAffine2D(Affine2DBase):
286-
def __init__(self, a: Affine2DBase, b: Affine2DBase, **kwargs) -> None: ...
285+
class CompositeAffine(AffineImmutable):
286+
def __init__(self, a: AffineImmutable, b: AffineImmutable, **kwargs) -> None: ...
287287
@property
288288
def depth(self) -> int: ...
289289

290+
class CompositeAffine2D(CompositeAffine):
291+
pass
292+
290293
def composite_transform_factory(a: Transform, b: Transform) -> Transform: ...
291294

292295
class BboxTransform(AffineImmutable):

0 commit comments

Comments
 (0)