7
7
BboxTransformTo , IdentityTransform , Transform , TransformWrapper
8
8
from matplotlib .projections import register_projection
9
9
10
- import numpy as npy
10
+ import numpy as np
11
11
12
12
# This example projection class is rather long, but it is designed to
13
13
# illustrate many features, not all of which will be used every time.
@@ -60,8 +60,8 @@ def cla(self):
60
60
# be changed by the user. This makes the math in the
61
61
# transformation itself easier, and since this is a toy
62
62
# 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 )
65
65
66
66
def cla (self ):
67
67
"""
@@ -79,8 +79,8 @@ def cla(self):
79
79
80
80
# self.grid(rcParams['axes.grid'])
81
81
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 )
84
84
85
85
def _set_lim_and_transforms (self ):
86
86
"""
@@ -117,8 +117,8 @@ def _set_lim_and_transforms(self):
117
117
# within the axes. The peculiar calculations of xscale and
118
118
# yscale are specific to a Aitoff-Hammer projection, so don't
119
119
# 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 )
122
122
self .transAffine = Affine2D () \
123
123
.scale (0.5 / xscale , 0.5 / yscale ) \
124
124
.translate (0.5 , 0.5 )
@@ -148,8 +148,8 @@ def _set_lim_and_transforms(self):
148
148
# pixels from the equator.
149
149
self ._xaxis_pretransform = \
150
150
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 )
153
153
self ._xaxis_transform = \
154
154
self ._xaxis_pretransform + \
155
155
self .transData
@@ -168,7 +168,7 @@ def _set_lim_and_transforms(self):
168
168
# (1, ymax). The goal of these transforms is to go from that
169
169
# space to display space. The tick labels will be offset 4
170
170
# 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 )
172
172
yaxis_space = Affine2D ().scale (1.0 , 1.1 )
173
173
self ._yaxis_transform = \
174
174
yaxis_stretch + \
@@ -265,8 +265,8 @@ def set_yscale(self, *args, **kwargs):
265
265
# set_xlim and set_ylim to ignore any input. This also applies to
266
266
# interactive panning and zooming in the GUI interfaces.
267
267
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 )
270
270
set_ylim = set_xlim
271
271
272
272
def format_coord (self , long , lat ):
@@ -276,8 +276,8 @@ def format_coord(self, long, lat):
276
276
277
277
In this case, we want them to be displayed in degrees N/S/E/W.
278
278
"""
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 )
281
281
if lat >= 0.0 :
282
282
ns = 'N'
283
283
else :
@@ -298,7 +298,7 @@ def __init__(self, round_to=1.0):
298
298
self ._round_to = round_to
299
299
300
300
def __call__ (self , x , pos = None ):
301
- degrees = (x / npy .pi ) * 180.0
301
+ degrees = (x / np .pi ) * 180.0
302
302
degrees = round (degrees / self ._round_to ) * self ._round_to
303
303
# \u00b0 : degree symbol
304
304
return u"%d\u00b0 " % degrees
@@ -316,7 +316,7 @@ class -- it provides a more convenient interface to set the
316
316
number = (360.0 / degrees ) + 1
317
317
self .xaxis .set_major_locator (
318
318
FixedLocator (
319
- npy .linspace (- npy .pi , npy .pi , number , True )[1 :- 1 ]))
319
+ np .linspace (- np .pi , np .pi , number , True )[1 :- 1 ]))
320
320
# Set the formatter to display the tick labels in degrees,
321
321
# rather than radians.
322
322
self .xaxis .set_major_formatter (self .DegreeFormatter (degrees ))
@@ -334,7 +334,7 @@ class -- it provides a more convenient interface than
334
334
number = (180.0 / degrees ) + 1
335
335
self .yaxis .set_major_locator (
336
336
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 ]))
338
338
# Set the formatter to display the tick labels in degrees,
339
339
# rather than radians.
340
340
self .yaxis .set_major_formatter (self .DegreeFormatter (degrees ))
@@ -351,7 +351,7 @@ def set_longitude_grid_ends(self, degrees):
351
351
class -- it provides an interface to something that has no
352
352
analogy in the base Axes class.
353
353
"""
354
- longitude_cap = degrees * (npy .pi / 180.0 )
354
+ longitude_cap = degrees * (np .pi / 180.0 )
355
355
# Change the xaxis gridlines transform so that it draws from
356
356
# -degrees to degrees, rather than -pi to pi.
357
357
self ._xaxis_pretransform \
@@ -412,13 +412,13 @@ def transform(self, ll):
412
412
413
413
# Pre-compute some values
414
414
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 )
417
417
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 )
422
422
423
423
# This is where things get interesting. With this projection,
424
424
# straight lines in data space become curves in display space.
@@ -451,10 +451,10 @@ def transform(self, xy):
451
451
452
452
quarter_x = 0.25 * x
453
453
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 )
458
458
transform .__doc__ = Transform .transform .__doc__
459
459
460
460
def inverted (self ):
0 commit comments