Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04b4381

Browse files
committed
Improved documentation and efficiency...
svn path=/branches/transforms/; revision=4766
1 parent e6a1f00 commit 04b4381

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

lib/matplotlib/scale.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@
77
from transforms import Transform, IdentityTransform
88

99
class ScaleBase(object):
10+
def get_transform(self):
11+
"""
12+
Return the transform object associated with this scale.
13+
"""
14+
raise NotImplementedError
15+
1016
def set_default_locators_and_formatters(self, axis):
17+
"""
18+
Set the locators and formatters that go with this scale.
19+
"""
1120
raise NotImplementedError
1221

1322
def limit_range_for_scale(self, vmin, vmax, minpos):
23+
"""
24+
Returns the range vmin, vmax, limited to the domain supported
25+
by this scale.
26+
"""
1427
return vmin, vmax
1528

1629
class LinearScale(ScaleBase):
@@ -285,6 +298,10 @@ class MercatorLatitudeScale(ScaleBase):
285298
The inverse scale function:
286299
atan(sinh(y))
287300
301+
Since the Mercator scale tends to infinity at +/- 90 degrees,
302+
there is user-defined threshold, above and below which nothing
303+
will be plotted. This defaults to +/- 85 degrees.
304+
288305
source:
289306
http://en.wikipedia.org/wiki/Mercator_projection
290307
"""
@@ -302,23 +319,27 @@ def __init__(self, thresh):
302319
def transform(self, a):
303320
masked = ma.masked_where((a < -self.thresh) | (a > self.thresh), a)
304321
if masked.mask.any():
305-
return ma.log(ma.abs(ma.tan(masked) + 1.0 / ma.cos(masked)))
322+
return ma.log(npy.abs(ma.tan(masked) + 1.0 / ma.cos(masked)))
306323
else:
307324
return npy.log(npy.abs(npy.tan(a) + 1.0 / npy.cos(a)))
308325

309326
def inverted(self):
310-
return MercatorLatitudeScale.InvertedMercatorLatitudeTransform()
327+
return MercatorLatitudeScale.InvertedMercatorLatitudeTransform(self.thresh)
311328

312329
class InvertedMercatorLatitudeTransform(Transform):
313330
input_dims = 1
314331
output_dims = 1
315332
is_separable = True
316333

334+
def __init__(self, thresh):
335+
Transform.__init__(self)
336+
self.thresh = thresh
337+
317338
def transform(self, a):
318339
return npy.arctan(npy.sinh(a))
319340

320341
def inverted(self):
321-
return MercatorLatitudeScale.MercatorLatitudeTransform()
342+
return MercatorLatitudeScale.MercatorLatitudeTransform(self.thresh)
322343

323344
def __init__(self, axis, **kwargs):
324345
thresh = kwargs.pop("thresh", (85 / 180.0) * npy.pi)
@@ -328,20 +349,16 @@ def __init__(self, axis, **kwargs):
328349
self._transform = self.MercatorLatitudeTransform(thresh)
329350

330351
def set_default_locators_and_formatters(self, axis):
331-
class ThetaFormatter(Formatter):
332-
"""
333-
Used to format the theta tick labels. Converts the native
334-
unit of radians into degrees and adds a degree symbol.
335-
"""
352+
class DegreeFormatter(Formatter):
336353
def __call__(self, x, pos=None):
337354
# \u00b0 : degree symbol
338355
return u"%d\u00b0" % ((x / npy.pi) * 180.0)
339356

340357
deg2rad = npy.pi / 180.0
341358
axis.set_major_locator(FixedLocator(
342359
npy.arange(-90, 90, 10) * deg2rad))
343-
axis.set_major_formatter(ThetaFormatter())
344-
axis.set_minor_formatter(ThetaFormatter())
360+
axis.set_major_formatter(DegreeFormatter())
361+
axis.set_minor_formatter(DegreeFormatter())
345362

346363
def get_transform(self):
347364
return self._transform
@@ -366,6 +383,12 @@ def scale_factory(scale, axis, **kwargs):
366383

367384
return _scale_mapping[scale](axis, **kwargs)
368385

386+
def register_scale(scale_class):
387+
"""
388+
Register a new kind of scale.
389+
"""
390+
_scale_mapping[scale_class.name] = scale_class
391+
369392
def get_scale_names():
370393
names = _scale_mapping.keys()
371394
names.sort()

0 commit comments

Comments
 (0)