Permalink
Browse files

Merge pull request #1579 from joferkington/fix-custom_projection_example

Updated custom_projection_example.py to work with v1.2 and newer
  • Loading branch information...
1 parent 7283784 commit ccb923ede43794aa27c1ac9eb396ebffe2cfe151 @pelson pelson committed with mdboom Dec 11, 2012
Showing with 28 additions and 6 deletions.
  1. +28 −6 examples/api/custom_projection_example.py
View
34 examples/api/custom_projection_example.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import matplotlib
from matplotlib.axes import Axes
from matplotlib.patches import Circle
from matplotlib.path import Path
@@ -385,9 +386,10 @@ class HammerTransform(Transform):
output_dims = 2
is_separable = False
- def transform(self, ll):
+ def transform_non_affine(self, ll):
"""
- Override the transform method to implement the custom transform.
+ Override the transform_non_affine method to implement the custom
+ transform.
The input and output are Nx2 numpy arrays.
"""
@@ -411,10 +413,25 @@ def transform(self, ll):
# differently-sized array, any transform that requires
# changing the length of the data array must happen within
# ``transform_path``.
- def transform_path(self, path):
- vertices = path.vertices
+ def transform_path_non_affine(self, path):
ipath = path.interpolated(path._interpolation_steps)
return Path(self.transform(ipath.vertices), ipath.codes)
+ transform_path_non_affine.__doc__ = \
+ Transform.transform_path_non_affine.__doc__
+
+ if matplotlib.__version__ < '1.2':
+ # Note: For compatibility with matplotlib v1.1 and older, you'll
+ # need to explicitly implement a ``transform`` method as well.
+ # Otherwise a ``NotImplementedError`` will be raised. This isn't
+ # necessary for v1.2 and newer, however.
+ transform = transform_non_affine
+
+ # Similarly, we need to explicitly override ``transform_path`` if
+ # compatibility with older matplotlib versions is needed. With v1.2
+ # and newer, only overriding the ``transform_path_non_affine``
+ # method is sufficient.
+ transform_path = transform_path_non_affine
+ transform_path.__doc__ = Transform.transform_path.__doc__
def inverted(self):
return HammerAxes.InvertedHammerTransform()
@@ -425,7 +442,7 @@ class InvertedHammerTransform(Transform):
output_dims = 2
is_separable = False
- def transform(self, xy):
+ def transform_non_affine(self, xy):
x = xy[:, 0:1]
y = xy[:, 1:2]
@@ -435,7 +452,12 @@ def transform(self, xy):
longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0)))
latitude = np.arcsin(y*z)
return np.concatenate((longitude, latitude), 1)
- transform.__doc__ = Transform.transform.__doc__
+ transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
+
+ # As before, we need to implement the "transform" method for
+ # compatibility with matplotlib v1.1 and older.
+ if matplotlib.__version__ < '1.2':
+ transform = transform_non_affine
def inverted(self):
# The inverse of the inverse is the original transform... ;)

0 comments on commit ccb923e

Please sign in to comment.