77 BboxTransformTo , IdentityTransform , Transform , TransformWrapper
88from matplotlib .projections import register_projection
99
10- import numpy as npy
10+ import numpy as np
1111
1212# This example projection class is rather long, but it is designed to
1313# illustrate many features, not all of which will be used every time.
@@ -60,8 +60,8 @@ def cla(self):
6060 # be changed by the user. This makes the math in the
6161 # transformation itself easier, and since this is a toy
6262 # example, the easier, the better.
63- Axes .set_xlim (self , - npy .pi , npy .pi )
64- Axes .set_ylim (self , - npy .pi / 2.0 , npy .pi / 2.0 )
63+ Axes .set_xlim (self , - np .pi , np .pi )
64+ Axes .set_ylim (self , - np .pi / 2.0 , np .pi / 2.0 )
6565
6666 def cla (self ):
6767 """
@@ -79,8 +79,8 @@ def cla(self):
7979
8080 # self.grid(rcParams['axes.grid'])
8181
82- Axes .set_xlim (self , - npy .pi , npy .pi )
83- Axes .set_ylim (self , - npy .pi / 2.0 , npy .pi / 2.0 )
82+ Axes .set_xlim (self , - np .pi , np .pi )
83+ Axes .set_ylim (self , - np .pi / 2.0 , np .pi / 2.0 )
8484
8585 def _set_lim_and_transforms (self ):
8686 """
@@ -117,8 +117,8 @@ def _set_lim_and_transforms(self):
117117 # within the axes. The peculiar calculations of xscale and
118118 # yscale are specific to a Aitoff-Hammer projection, so don't
119119 # worry about them too much.
120- xscale = 2.0 * npy .sqrt (2.0 ) * npy .sin (0.5 * npy .pi )
121- yscale = npy .sqrt (2.0 ) * npy .sin (0.5 * npy .pi )
120+ xscale = 2.0 * np .sqrt (2.0 ) * np .sin (0.5 * np .pi )
121+ yscale = np .sqrt (2.0 ) * np .sin (0.5 * np .pi )
122122 self .transAffine = Affine2D () \
123123 .scale (0.5 / xscale , 0.5 / yscale ) \
124124 .translate (0.5 , 0.5 )
@@ -148,8 +148,8 @@ def _set_lim_and_transforms(self):
148148 # pixels from the equator.
149149 self ._xaxis_pretransform = \
150150 Affine2D () \
151- .scale (1.0 , npy .pi ) \
152- .translate (0.0 , - npy .pi )
151+ .scale (1.0 , np .pi ) \
152+ .translate (0.0 , - np .pi )
153153 self ._xaxis_transform = \
154154 self ._xaxis_pretransform + \
155155 self .transData
@@ -168,7 +168,7 @@ def _set_lim_and_transforms(self):
168168 # (1, ymax). The goal of these transforms is to go from that
169169 # space to display space. The tick labels will be offset 4
170170 # pixels from the edge of the axes ellipse.
171- yaxis_stretch = Affine2D ().scale (npy .pi * 2.0 , 1.0 ).translate (- npy .pi , 0.0 )
171+ yaxis_stretch = Affine2D ().scale (np .pi * 2.0 , 1.0 ).translate (- np .pi , 0.0 )
172172 yaxis_space = Affine2D ().scale (1.0 , 1.1 )
173173 self ._yaxis_transform = \
174174 yaxis_stretch + \
@@ -265,8 +265,8 @@ def set_yscale(self, *args, **kwargs):
265265 # set_xlim and set_ylim to ignore any input. This also applies to
266266 # interactive panning and zooming in the GUI interfaces.
267267 def set_xlim (self , * args , ** kwargs ):
268- Axes .set_xlim (self , - npy .pi , npy .pi )
269- Axes .set_ylim (self , - npy .pi / 2.0 , npy .pi / 2.0 )
268+ Axes .set_xlim (self , - np .pi , np .pi )
269+ Axes .set_ylim (self , - np .pi / 2.0 , np .pi / 2.0 )
270270 set_ylim = set_xlim
271271
272272 def format_coord (self , long , lat ):
@@ -276,8 +276,8 @@ def format_coord(self, long, lat):
276276
277277 In this case, we want them to be displayed in degrees N/S/E/W.
278278 """
279- long = long * (180.0 / npy .pi )
280- lat = lat * (180.0 / npy .pi )
279+ long = long * (180.0 / np .pi )
280+ lat = lat * (180.0 / np .pi )
281281 if lat >= 0.0 :
282282 ns = 'N'
283283 else :
@@ -298,7 +298,7 @@ def __init__(self, round_to=1.0):
298298 self ._round_to = round_to
299299
300300 def __call__ (self , x , pos = None ):
301- degrees = (x / npy .pi ) * 180.0
301+ degrees = (x / np .pi ) * 180.0
302302 degrees = round (degrees / self ._round_to ) * self ._round_to
303303 # \u00b0 : degree symbol
304304 return u"%d\u00b0 " % degrees
@@ -316,7 +316,7 @@ class -- it provides a more convenient interface to set the
316316 number = (360.0 / degrees ) + 1
317317 self .xaxis .set_major_locator (
318318 FixedLocator (
319- npy .linspace (- npy .pi , npy .pi , number , True )[1 :- 1 ]))
319+ np .linspace (- np .pi , np .pi , number , True )[1 :- 1 ]))
320320 # Set the formatter to display the tick labels in degrees,
321321 # rather than radians.
322322 self .xaxis .set_major_formatter (self .DegreeFormatter (degrees ))
@@ -334,7 +334,7 @@ class -- it provides a more convenient interface than
334334 number = (180.0 / degrees ) + 1
335335 self .yaxis .set_major_locator (
336336 FixedLocator (
337- npy .linspace (- npy .pi / 2.0 , npy .pi / 2.0 , number , True )[1 :- 1 ]))
337+ np .linspace (- np .pi / 2.0 , np .pi / 2.0 , number , True )[1 :- 1 ]))
338338 # Set the formatter to display the tick labels in degrees,
339339 # rather than radians.
340340 self .yaxis .set_major_formatter (self .DegreeFormatter (degrees ))
@@ -351,7 +351,7 @@ def set_longitude_grid_ends(self, degrees):
351351 class -- it provides an interface to something that has no
352352 analogy in the base Axes class.
353353 """
354- longitude_cap = degrees * (npy .pi / 180.0 )
354+ longitude_cap = degrees * (np .pi / 180.0 )
355355 # Change the xaxis gridlines transform so that it draws from
356356 # -degrees to degrees, rather than -pi to pi.
357357 self ._xaxis_pretransform \
@@ -412,13 +412,13 @@ def transform(self, ll):
412412
413413 # Pre-compute some values
414414 half_long = longitude / 2.0
415- cos_latitude = npy .cos (latitude )
416- sqrt2 = npy .sqrt (2.0 )
415+ cos_latitude = np .cos (latitude )
416+ sqrt2 = np .sqrt (2.0 )
417417
418- alpha = 1.0 + cos_latitude * npy .cos (half_long )
419- x = (2.0 * sqrt2 ) * (cos_latitude * npy .sin (half_long )) / alpha
420- y = (sqrt2 * npy .sin (latitude )) / alpha
421- return npy .concatenate ((x , y ), 1 )
418+ alpha = 1.0 + cos_latitude * np .cos (half_long )
419+ x = (2.0 * sqrt2 ) * (cos_latitude * np .sin (half_long )) / alpha
420+ y = (sqrt2 * np .sin (latitude )) / alpha
421+ return np .concatenate ((x , y ), 1 )
422422
423423 # This is where things get interesting. With this projection,
424424 # straight lines in data space become curves in display space.
@@ -451,10 +451,10 @@ def transform(self, xy):
451451
452452 quarter_x = 0.25 * x
453453 half_y = 0.5 * y
454- z = npy .sqrt (1.0 - quarter_x * quarter_x - half_y * half_y )
455- longitude = 2 * npy .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
456- latitude = npy .arcsin (y * z )
457- return npy .concatenate ((longitude , latitude ), 1 )
454+ z = np .sqrt (1.0 - quarter_x * quarter_x - half_y * half_y )
455+ longitude = 2 * np .arctan ((z * x ) / (2.0 * (2.0 * z * z - 1.0 )))
456+ latitude = np .arcsin (y * z )
457+ return np .concatenate ((longitude , latitude ), 1 )
458458 transform .__doc__ = Transform .transform .__doc__
459459
460460 def inverted (self ):
0 commit comments