11from __future__ import unicode_literals
22
3+ import matplotlib
34from matplotlib .axes import Axes
45from matplotlib .patches import Circle
56from matplotlib .path import Path
@@ -385,9 +386,10 @@ class HammerTransform(Transform):
385386 output_dims = 2
386387 is_separable = False
387388
388- def transform (self , ll ):
389+ def transform_non_affine (self , ll ):
389390 """
390- Override the transform method to implement the custom transform.
391+ Override the transform_non_affine method to implement the custom
392+ transform.
391393
392394 The input and output are Nx2 numpy arrays.
393395 """
@@ -411,10 +413,25 @@ def transform(self, ll):
411413 # differently-sized array, any transform that requires
412414 # changing the length of the data array must happen within
413415 # ``transform_path``.
414- def transform_path (self , path ):
415- vertices = path .vertices
416+ def transform_path_non_affine (self , path ):
416417 ipath = path .interpolated (path ._interpolation_steps )
417418 return Path (self .transform (ipath .vertices ), ipath .codes )
419+ transform_path_non_affine .__doc__ = \
420+ Transform .transform_path_non_affine .__doc__
421+
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__
418435
419436 def inverted (self ):
420437 return HammerAxes .InvertedHammerTransform ()
@@ -425,7 +442,7 @@ class InvertedHammerTransform(Transform):
425442 output_dims = 2
426443 is_separable = False
427444
428- def transform (self , xy ):
445+ def transform_non_affine (self , xy ):
429446 x = xy [:, 0 :1 ]
430447 y = xy [:, 1 :2 ]
431448
@@ -435,7 +452,12 @@ def transform(self, xy):
435452 longitude = 2 * np .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
436453 latitude = np .arcsin (y * z )
437454 return np .concatenate ((longitude , latitude ), 1 )
438- transform .__doc__ = Transform .transform .__doc__
455+ transform_non_affine .__doc__ = Transform .transform_non_affine .__doc__
456+
457+ # As before, we need to implement the "transform" method for
458+ # compatibility with matplotlib v1.1 and older.
459+ if matplotlib .__version__ < '1.2' :
460+ transform = transform_non_affine
439461
440462 def inverted (self ):
441463 # The inverse of the inverse is the original transform... ;)
0 commit comments