@@ -385,9 +385,10 @@ class HammerTransform(Transform):
385
385
output_dims = 2
386
386
is_separable = False
387
387
388
- def transform (self , ll ):
388
+ def transform_non_affine (self , ll ):
389
389
"""
390
- Override the transform method to implement the custom transform.
390
+ Override the transform_non_affine method to implement the custom
391
+ transform.
391
392
392
393
The input and output are Nx2 numpy arrays.
393
394
"""
@@ -404,17 +405,32 @@ def transform(self, ll):
404
405
y = (sqrt2 * np .sin (latitude )) / alpha
405
406
return np .concatenate ((x , y ), 1 )
406
407
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
+
407
416
# This is where things get interesting. With this projection,
408
417
# straight lines in data space become curves in display space.
409
418
# This is done by interpolating new values between the input
410
419
# values of the data. Since ``transform`` must not return a
411
420
# differently-sized array, any transform that requires
412
421
# changing the length of the data array must happen within
413
422
# ``transform_path``.
414
- def transform_path (self , path ):
415
- vertices = path .vertices
423
+ def transform_path_non_affine (self , path ):
416
424
ipath = path .interpolated (path ._interpolation_steps )
417
425
return Path (self .transform (ipath .vertices ), ipath .codes )
426
+ transform_path_non_affine .__doc__ = \
427
+ Transform .transform_path_non_affine .__doc__
428
+
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__
418
434
419
435
def inverted (self ):
420
436
return HammerAxes .InvertedHammerTransform ()
@@ -425,7 +441,7 @@ class InvertedHammerTransform(Transform):
425
441
output_dims = 2
426
442
is_separable = False
427
443
428
- def transform (self , xy ):
444
+ def transform_non_affine (self , xy ):
429
445
x = xy [:, 0 :1 ]
430
446
y = xy [:, 1 :2 ]
431
447
@@ -435,7 +451,11 @@ def transform(self, xy):
435
451
longitude = 2 * np .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
436
452
latitude = np .arcsin (y * z )
437
453
return np .concatenate ((longitude , latitude ), 1 )
438
- transform .__doc__ = Transform .transform .__doc__
454
+ transform_non_affine .__doc__ = Transform .transform_non_affine .__doc__
455
+
456
+ # As before, we need to implement the "transform" method for
457
+ # compatibility with matplotlib v1.1 and older.
458
+ transform = transform_non_affine
439
459
440
460
def inverted (self ):
441
461
# The inverse of the inverse is the original transform... ;)
0 commit comments