Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c13f629

Browse filesBrowse files
committed
Merge pull request matplotlib#1579 from joferkington/fix-custom_projection_example
Updated custom_projection_example.py to work with v1.2 and newer
2 parents 2ccc3ba + 2a73c12 commit c13f629
Copy full SHA for c13f629

File tree

Expand file treeCollapse file tree

1 file changed

+28
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-6
lines changed

‎examples/api/custom_projection_example.py

Copy file name to clipboardExpand all lines: examples/api/custom_projection_example.py
+28-6Lines changed: 28 additions & 6 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
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.