|
1 | 1 | from __future__ import unicode_literals |
2 | 2 |
|
3 | | -import matplotlib.pyplot as plt |
4 | 3 | from matplotlib.axes import Axes |
5 | 4 | from matplotlib.patches import Circle |
6 | 5 | from matplotlib.path import Path |
| 6 | +from matplotlib.ticker import NullLocator, Formatter, FixedLocator |
7 | 7 | from matplotlib.transforms import Affine2D, BboxTransformTo, Transform |
8 | 8 | from matplotlib.projections import register_projection |
9 | 9 | import matplotlib.spines as mspines |
@@ -55,8 +55,8 @@ def cla(self): |
55 | 55 | self.set_longitude_grid_ends(75) |
56 | 56 |
|
57 | 57 | # Turn off minor ticking altogether |
58 | | - self.xaxis.set_minor_locator(plt.NullLocator()) |
59 | | - self.yaxis.set_minor_locator(plt.NullLocator()) |
| 58 | + self.xaxis.set_minor_locator(NullLocator()) |
| 59 | + self.yaxis.set_minor_locator(NullLocator()) |
60 | 60 |
|
61 | 61 | # Do not display ticks -- we only want gridlines and text |
62 | 62 | self.xaxis.set_ticks_position('none') |
@@ -282,7 +282,7 @@ def format_coord(self, long, lat): |
282 | 282 | # \u00b0 : degree symbol |
283 | 283 | return '%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(long), ew) |
284 | 284 |
|
285 | | - class DegreeFormatter(plt.Formatter): |
| 285 | + class DegreeFormatter(Formatter): |
286 | 286 | """ |
287 | 287 | This is a custom formatter that converts the native unit of |
288 | 288 | radians into (truncated) degrees and adds a degree symbol. |
@@ -326,7 +326,7 @@ class -- it provides a more convenient interface than |
326 | 326 | # by degrees. |
327 | 327 | number = (180.0 / degrees) + 1 |
328 | 328 | self.yaxis.set_major_locator( |
329 | | - plt.FixedLocator( |
| 329 | + FixedLocator( |
330 | 330 | np.linspace(-np.pi / 2.0, np.pi / 2.0, number, True)[1:-1])) |
331 | 331 | # Set the formatter to display the tick labels in degrees, |
332 | 332 | # rather than radians. |
@@ -446,10 +446,12 @@ def inverted(self): |
446 | 446 | # it. |
447 | 447 | register_projection(HammerAxes) |
448 | 448 |
|
449 | | -# Now make a simple example using the custom projection. |
450 | | -plt.subplot(111, projection="custom_hammer") |
451 | | -p = plt.plot([-1, 1, 1], [-1, -1, 1], "o-") |
452 | | -plt.grid(True) |
| 449 | +if __name__ == '__main__': |
| 450 | + import matplotlib.pyplot as plt |
| 451 | + # Now make a simple example using the custom projection. |
| 452 | + plt.subplot(111, projection="custom_hammer") |
| 453 | + p = plt.plot([-1, 1, 1], [-1, -1, 1], "o-") |
| 454 | + plt.grid(True) |
453 | 455 |
|
454 | | -plt.show() |
| 456 | + plt.show() |
455 | 457 |
|
0 commit comments