Skip to content

Commit bdcd9fc

Browse files
authored
Simplify transforms addition. (#16150)
Simplify transforms addition.
2 parents d774072 + 2dabe85 commit bdcd9fc

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,7 @@ def _set_lim_and_transforms(self):
820820
.scale(self._default_theta_direction, 1.0)
821821
self._theta_offset = mtransforms.Affine2D() \
822822
.translate(self._default_theta_offset, 0.0)
823-
self.transShift = mtransforms.composite_transform_factory(
824-
self._direction,
825-
self._theta_offset)
823+
self.transShift = self._direction + self._theta_offset
826824
# A view limit shifted to the correct location after accounting for
827825
# orientation and offset.
828826
self._realViewLim = mtransforms.TransformedBbox(self.viewLim,

lib/matplotlib/transforms.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,23 +1243,11 @@ def __init_subclass__(cls):
12431243

12441244
def __add__(self, other):
12451245
"""
1246-
Composes two transforms together such that *self* is followed
1247-
by *other*.
1246+
Compose two transforms together so that *self* is followed by *other*.
12481247
"""
1249-
if isinstance(other, Transform):
1250-
return composite_transform_factory(self, other)
1251-
raise TypeError(
1252-
"Can not add Transform to object of type '%s'" % type(other))
1253-
1254-
def __radd__(self, other):
1255-
"""
1256-
Composes two transforms together such that *self* is followed
1257-
by *other*.
1258-
"""
1259-
if isinstance(other, Transform):
1260-
return composite_transform_factory(other, self)
1261-
raise TypeError(
1262-
"Can not add Transform to object of type '%s'" % type(other))
1248+
return (composite_transform_factory(self, other)
1249+
if isinstance(other, Transform) else
1250+
NotImplemented)
12631251

12641252
# Equality is based on object identity for `Transform`s (so we don't
12651253
# override `__eq__`), but some subclasses, such as TransformWrapper &
@@ -2285,9 +2273,9 @@ def __init__(self, a, b, **kwargs):
22852273
Create a new composite transform that is the result of
22862274
applying transform *a* then transform *b*.
22872275
2288-
You will generally not call this constructor directly but use the
2289-
`composite_transform_factory` function instead, which can automatically
2290-
choose the best kind of composite transform instance to create.
2276+
You will generally not call this constructor directly but write ``a +
2277+
b`` instead, which will automatically choose the best kind of composite
2278+
transform instance to create.
22912279
"""
22922280
if a.output_dims != b.input_dims:
22932281
raise ValueError("The output dimension of 'a' must be equal to "
@@ -2401,13 +2389,11 @@ class CompositeAffine2D(Affine2DBase):
24012389
def __init__(self, a, b, **kwargs):
24022390
"""
24032391
Create a new composite transform that is the result of
2404-
applying transform *a* then transform *b*.
2405-
2406-
Both *a* and *b* must be instances of :class:`Affine2DBase`.
2392+
applying `Affine2DBase` *a* then `Affine2DBase` *b*.
24072393
2408-
You will generally not call this constructor directly but use the
2409-
`composite_transform_factory` function instead, which can automatically
2410-
choose the best kind of composite transform instance to create.
2394+
You will generally not call this constructor directly but write ``a +
2395+
b`` instead, which will automatically choose the best kind of composite
2396+
transform instance to create.
24112397
"""
24122398
if not a.is_affine or not b.is_affine:
24132399
raise ValueError("'a' and 'b' must be affine transforms")

0 commit comments

Comments
 (0)