1
1
from __future__ import unicode_literals
2
2
3
+ import matplotlib
3
4
from matplotlib .axes import Axes
4
5
from matplotlib .patches import Circle
5
6
from matplotlib .path import Path
@@ -385,9 +386,10 @@ class HammerTransform(Transform):
385
386
output_dims = 2
386
387
is_separable = False
387
388
388
- def transform (self , ll ):
389
+ def transform_non_affine (self , ll ):
389
390
"""
390
- Override the transform method to implement the custom transform.
391
+ Override the transform_non_affine method to implement the custom
392
+ transform.
391
393
392
394
The input and output are Nx2 numpy arrays.
393
395
"""
@@ -411,10 +413,25 @@ def transform(self, ll):
411
413
# differently-sized array, any transform that requires
412
414
# changing the length of the data array must happen within
413
415
# ``transform_path``.
414
- def transform_path (self , path ):
415
- vertices = path .vertices
416
+ def transform_path_non_affine (self , path ):
416
417
ipath = path .interpolated (path ._interpolation_steps )
417
418
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__
418
435
419
436
def inverted (self ):
420
437
return HammerAxes .InvertedHammerTransform ()
@@ -425,7 +442,7 @@ class InvertedHammerTransform(Transform):
425
442
output_dims = 2
426
443
is_separable = False
427
444
428
- def transform (self , xy ):
445
+ def transform_non_affine (self , xy ):
429
446
x = xy [:, 0 :1 ]
430
447
y = xy [:, 1 :2 ]
431
448
@@ -435,7 +452,12 @@ def transform(self, xy):
435
452
longitude = 2 * np .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
436
453
latitude = np .arcsin (y * z )
437
454
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
439
461
440
462
def inverted (self ):
441
463
# The inverse of the inverse is the original transform... ;)
0 commit comments