Skip to content

Commit 2a73c12

Browse files
committed
Wrapped backward-compatibility code in a version conditional
1 parent 86fd746 commit 2a73c12

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

examples/api/custom_projection_example.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import unicode_literals
22

3+
import matplotlib
34
from matplotlib.axes import Axes
45
from matplotlib.patches import Circle
56
from matplotlib.path import Path
@@ -405,14 +406,6 @@ def transform_non_affine(self, ll):
405406
y = (sqrt2 * np.sin(latitude)) / alpha
406407
return np.concatenate((x, y), 1)
407408

408-
# Note: For compatibility with matplotlib v1.1 and older, you'll need
409-
# to explicitly implement a ``transform`` method as well. Otherwise a
410-
# ``NotImplementedError`` will be raised. This isn't necessary for v1.2
411-
# and newer, however.
412-
def transform(self, values):
413-
return self.transform_affine(self.transform_non_affine(values))
414-
transform.__doc__ = Transform.transform.__doc__
415-
416409
# This is where things get interesting. With this projection,
417410
# straight lines in data space become curves in display space.
418411
# This is done by interpolating new values between the input
@@ -426,11 +419,19 @@ def transform_path_non_affine(self, path):
426419
transform_path_non_affine.__doc__ = \
427420
Transform.transform_path_non_affine.__doc__
428421

429-
# Once again, for compatibility with matplotlib v1.1 and older, we need
430-
# to explicitly override ``transform_path``. With v1.2 and newer, only
431-
# overriding the ``transform_path_non_affine`` method is sufficient.
432-
transform_path = transform_path_non_affine
433-
transform_path.__doc__ = Transform.transform_path.__doc__
422+
if matplotlib.__version__ < '1.2':
423+
# Note: For compatibility with matplotlib v1.1 and older, you'll
424+
# need to explicitly implement a ``transform`` method as well.
425+
# Otherwise a ``NotImplementedError`` will be raised. This isn't
426+
# necessary for v1.2 and newer, however.
427+
transform = transform_non_affine
428+
429+
# Similarly, we need to explicitly override ``transform_path`` if
430+
# compatibility with older matplotlib versions is needed. With v1.2
431+
# and newer, only overriding the ``transform_path_non_affine``
432+
# method is sufficient.
433+
transform_path = transform_path_non_affine
434+
transform_path.__doc__ = Transform.transform_path.__doc__
434435

435436
def inverted(self):
436437
return HammerAxes.InvertedHammerTransform()
@@ -455,7 +456,8 @@ def transform_non_affine(self, xy):
455456

456457
# As before, we need to implement the "transform" method for
457458
# compatibility with matplotlib v1.1 and older.
458-
transform = transform_non_affine
459+
if matplotlib.__version__ < '1.2':
460+
transform = transform_non_affine
459461

460462
def inverted(self):
461463
# The inverse of the inverse is the original transform... ;)

0 commit comments

Comments
 (0)