7
7
Mercator Projection.
8
8
9
9
Unless you are making special use of the `~.Transform` class, you probably
10
- don't need to use this verbose method, and instead can use
11
- `~.matplotlib.scale.FuncScale` and the ``'function'`` option of
12
- `~.matplotlib.axes.Axes.set_xscale` and `~.matplotlib.axes.Axes.set_yscale`.
10
+ don't need to use this verbose method, and instead can use `~.scale.FuncScale`
11
+ and the ``'function'`` option of `~.Axes.set_xscale` and `~.Axes.set_yscale`.
13
12
See the last example in :doc:`/gallery/scales/scales`.
14
13
"""
15
14
16
15
import numpy as np
17
16
from numpy import ma
18
17
from matplotlib import scale as mscale
19
18
from matplotlib import transforms as mtransforms
20
- from matplotlib .ticker import Formatter , FixedLocator
19
+ from matplotlib .ticker import FixedLocator , FuncFormatter
21
20
from matplotlib import rcParams
22
21
23
22
24
- # BUG: this example fails with any other setting of axisbelow
25
- rcParams ['axes.axisbelow' ] = False
26
-
27
-
28
23
class MercatorLatitudeScale (mscale .ScaleBase ):
29
24
"""
30
25
Scales data in range -pi/2 to pi/2 (-90 to 90 degrees) using
31
- the system used to scale latitudes in a Mercator projection.
26
+ the system used to scale latitudes in a Mercator__ projection.
32
27
33
28
The scale function:
34
29
ln(tan(y) + sec(y))
@@ -40,8 +35,7 @@ class MercatorLatitudeScale(mscale.ScaleBase):
40
35
there is user-defined threshold, above and below which nothing
41
36
will be plotted. This defaults to +/- 85 degrees.
42
37
43
- source:
44
- http://en.wikipedia.org/wiki/Mercator_projection
38
+ __ http://en.wikipedia.org/wiki/Mercator_projection
45
39
"""
46
40
47
41
# The scale class must have a member ``name`` that defines the string used
@@ -77,21 +71,16 @@ def set_default_locators_and_formatters(self, axis):
77
71
scale. This is only required if the scale requires custom
78
72
locators and formatters. Writing custom locators and
79
73
formatters is rather outside the scope of this example, but
80
- there are many helpful examples in ``ticker.py` `.
74
+ there are many helpful examples in :mod:`.ticker `.
81
75
82
- In our case, the Mercator example uses a fixed locator from
83
- -90 to 90 degrees and a custom formatter class to put convert
84
- the radians to degrees and put a degree symbol after the
85
- value::
76
+ In our case, the Mercator example uses a fixed locator from -90 to 90
77
+ degrees and a custom formatter to convert the radians to degrees and
78
+ put a degree symbol after the value.
86
79
"""
87
- class DegreeFormatter (Formatter ):
88
- def __call__ (self , x , pos = None ):
89
- return "%d\N{DEGREE SIGN} " % np .degrees (x )
90
-
91
- axis .set_major_locator (FixedLocator (
92
- np .radians (np .arange (- 90 , 90 , 10 ))))
93
- axis .set_major_formatter (DegreeFormatter ())
94
- axis .set_minor_formatter (DegreeFormatter ())
80
+ fmt = FuncFormatter (
81
+ lambda x , pos = None : f"{ np .degrees (x ):.0f} \N{DEGREE SIGN} " )
82
+ axis .set (major_locator = FixedLocator (np .radians (range (- 90 , 90 , 10 ))),
83
+ major_formatter = fmt , minor_formatter = fmt )
95
84
96
85
def limit_range_for_scale (self , vmin , vmax , minpos ):
97
86
"""
@@ -176,7 +165,7 @@ def inverted(self):
176
165
177
166
plt .xlabel ('Longitude' )
178
167
plt .ylabel ('Latitude' )
179
- plt .title ('Mercator: Projection of the Oppressor ' )
168
+ plt .title ('Mercator projection ' )
180
169
plt .grid (True )
181
170
182
171
plt .show ()
0 commit comments