11from __future__ import print_function
2- import textwrap
2+
33import numpy as np
44from numpy import ma
5- MaskedArray = ma .MaskedArray
65
7- from cbook import dedent
8- from ticker import NullFormatter , ScalarFormatter , LogFormatterMathtext , Formatter
9- from ticker import NullLocator , LogLocator , AutoLocator , SymmetricalLogLocator , FixedLocator
10- from ticker import is_decade
11- from transforms import Transform , IdentityTransform
6+ from matplotlib .cbook import dedent
7+ from matplotlib .ticker import (NullFormatter , ScalarFormatter ,
8+ LogFormatterMathtext )
9+ from matplotlib .ticker import (NullLocator , LogLocator , AutoLocator ,
10+ SymmetricalLogLocator )
11+ from matplotlib .transforms import Transform , IdentityTransform
1212from matplotlib import docstring
1313
14+
1415class ScaleBase (object ):
1516 """
1617 The base class for all scales.
@@ -31,15 +32,15 @@ def get_transform(self):
3132 Return the :class:`~matplotlib.transforms.Transform` object
3233 associated with this scale.
3334 """
34- raise NotImplementedError
35+ raise NotImplementedError ()
3536
3637 def set_default_locators_and_formatters (self , axis ):
3738 """
3839 Set the :class:`~matplotlib.ticker.Locator` and
3940 :class:`~matplotlib.ticker.Formatter` objects on the given
4041 axis to match this scale.
4142 """
42- raise NotImplementedError
43+ raise NotImplementedError ()
4344
4445 def limit_range_for_scale (self , vmin , vmax , minpos ):
4546 """
@@ -51,6 +52,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
5152 """
5253 return vmin , vmax
5354
55+
5456class LinearScale (ScaleBase ):
5557 """
5658 The default linear scale.
@@ -90,10 +92,12 @@ def _mask_non_positives(a):
9092 return ma .MaskedArray (a , mask = mask )
9193 return a
9294
95+
9396def _clip_non_positives (a ):
9497 a [a <= 0.0 ] = 1e-300
9598 return a
9699
100+
97101class LogScale (ScaleBase ):
98102 """
99103 A standard logarithmic scale. Care is taken so non-positive
@@ -116,21 +120,20 @@ class LogTransformBase(Transform):
116120 output_dims = 1
117121 is_separable = True
118122 has_inverse = True
119-
123+
120124 def __init__ (self , nonpos ):
121125 Transform .__init__ (self )
122126 if nonpos == 'mask' :
123127 self ._handle_nonpos = _mask_non_positives
124128 else :
125129 self ._handle_nonpos = _clip_non_positives
126130
127-
128131 class Log10Transform (LogTransformBase ):
129132 base = 10.0
130133
131- def transform (self , a ):
134+ def transform_non_affine (self , a ):
132135 a = self ._handle_nonpos (a * 10.0 )
133- if isinstance (a , MaskedArray ):
136+ if isinstance (a , ma . MaskedArray ):
134137 return ma .log10 (a )
135138 return np .log10 (a )
136139
@@ -141,9 +144,10 @@ class InvertedLog10Transform(Transform):
141144 input_dims = 1
142145 output_dims = 1
143146 is_separable = True
147+ has_inverse = True
144148 base = 10.0
145149
146- def transform (self , a ):
150+ def transform_non_affine (self , a ):
147151 return ma .power (10.0 , a ) / 10.0
148152
149153 def inverted (self ):
@@ -152,9 +156,9 @@ def inverted(self):
152156 class Log2Transform (LogTransformBase ):
153157 base = 2.0
154158
155- def transform (self , a ):
159+ def transform_non_affine (self , a ):
156160 a = self ._handle_nonpos (a * 2.0 )
157- if isinstance (a , MaskedArray ):
161+ if isinstance (a , ma . MaskedArray ):
158162 return ma .log (a ) / np .log (2 )
159163 return np .log2 (a )
160164
@@ -165,9 +169,10 @@ class InvertedLog2Transform(Transform):
165169 input_dims = 1
166170 output_dims = 1
167171 is_separable = True
172+ has_inverse = True
168173 base = 2.0
169174
170- def transform (self , a ):
175+ def transform_non_affine (self , a ):
171176 return ma .power (2.0 , a ) / 2.0
172177
173178 def inverted (self ):
@@ -176,9 +181,9 @@ def inverted(self):
176181 class NaturalLogTransform (LogTransformBase ):
177182 base = np .e
178183
179- def transform (self , a ):
184+ def transform_non_affine (self , a ):
180185 a = self ._handle_nonpos (a * np .e )
181- if isinstance (a , MaskedArray ):
186+ if isinstance (a , ma . MaskedArray ):
182187 return ma .log (a )
183188 return np .log (a )
184189
@@ -189,9 +194,10 @@ class InvertedNaturalLogTransform(Transform):
189194 input_dims = 1
190195 output_dims = 1
191196 is_separable = True
197+ has_inverse = True
192198 base = np .e
193199
194- def transform (self , a ):
200+ def transform_non_affine (self , a ):
195201 return ma .power (np .e , a ) / np .e
196202
197203 def inverted (self ):
@@ -201,7 +207,8 @@ class LogTransform(Transform):
201207 input_dims = 1
202208 output_dims = 1
203209 is_separable = True
204-
210+ has_inverse = True
211+
205212 def __init__ (self , base , nonpos ):
206213 Transform .__init__ (self )
207214 self .base = base
@@ -210,9 +217,9 @@ def __init__(self, base, nonpos):
210217 else :
211218 self ._handle_nonpos = _clip_non_positives
212219
213- def transform (self , a ):
220+ def transform_non_affine (self , a ):
214221 a = self ._handle_nonpos (a * self .base )
215- if isinstance (a , MaskedArray ):
222+ if isinstance (a , ma . MaskedArray ):
216223 return ma .log (a ) / np .log (self .base )
217224 return np .log (a ) / np .log (self .base )
218225
@@ -223,18 +230,18 @@ class InvertedLogTransform(Transform):
223230 input_dims = 1
224231 output_dims = 1
225232 is_separable = True
226-
233+ has_inverse = True
234+
227235 def __init__ (self , base ):
228236 Transform .__init__ (self )
229237 self .base = base
230238
231- def transform (self , a ):
239+ def transform_non_affine (self , a ):
232240 return ma .power (self .base , a ) / self .base
233241
234242 def inverted (self ):
235243 return LogScale .LogTransform (self .base )
236-
237-
244+
238245 def __init__ (self , axis , ** kwargs ):
239246 """
240247 *basex*/*basey*:
@@ -318,7 +325,7 @@ class SymmetricalLogTransform(Transform):
318325 output_dims = 1
319326 is_separable = True
320327 has_inverse = True
321-
328+
322329 def __init__ (self , base , linthresh , linscale ):
323330 Transform .__init__ (self )
324331 self .base = base
@@ -327,7 +334,7 @@ def __init__(self, base, linthresh, linscale):
327334 self ._linscale_adj = (linscale / (1.0 - self .base ** - 1 ))
328335 self ._log_base = np .log (base )
329336
330- def transform (self , a ):
337+ def transform_non_affine (self , a ):
331338 sign = np .sign (a )
332339 masked = ma .masked_inside (a , - self .linthresh , self .linthresh , copy = False )
333340 log = sign * self .linthresh * (
@@ -346,7 +353,8 @@ class InvertedSymmetricalLogTransform(Transform):
346353 input_dims = 1
347354 output_dims = 1
348355 is_separable = True
349-
356+ has_inverse = True
357+
350358 def __init__ (self , base , linthresh , linscale ):
351359 Transform .__init__ (self )
352360 symlog = SymmetricalLogScale .SymmetricalLogTransform (base , linthresh , linscale )
@@ -356,7 +364,7 @@ def __init__(self, base, linthresh, linscale):
356364 self .linscale = linscale
357365 self ._linscale_adj = (linscale / (1.0 - self .base ** - 1 ))
358366
359- def transform (self , a ):
367+ def transform_non_affine (self , a ):
360368 sign = np .sign (a )
361369 masked = ma .masked_inside (a , - self .invlinthresh , self .invlinthresh , copy = False )
362370 exp = sign * self .linthresh * (
@@ -436,17 +444,19 @@ def get_transform(self):
436444 return self ._transform
437445
438446
439-
440447_scale_mapping = {
441448 'linear' : LinearScale ,
442449 'log' : LogScale ,
443450 'symlog' : SymmetricalLogScale
444451 }
452+
453+
445454def get_scale_names ():
446455 names = _scale_mapping .keys ()
447456 names .sort ()
448457 return names
449458
459+
450460def scale_factory (scale , axis , ** kwargs ):
451461 """
452462 Return a scale class by name.
@@ -464,6 +474,7 @@ def scale_factory(scale, axis, **kwargs):
464474scale_factory .__doc__ = dedent (scale_factory .__doc__ ) % \
465475 {'names' : " | " .join (get_scale_names ())}
466476
477+
467478def register_scale (scale_class ):
468479 """
469480 Register a new kind of scale.
@@ -472,6 +483,7 @@ def register_scale(scale_class):
472483 """
473484 _scale_mapping [scale_class .name ] = scale_class
474485
486+
475487def get_scale_docs ():
476488 """
477489 Helper function for generating docstrings related to scales.
@@ -488,6 +500,7 @@ def get_scale_docs():
488500 docs .append ("" )
489501 return "\n " .join (docs )
490502
503+
491504docstring .interpd .update (
492505 scale = ' | ' .join ([repr (x ) for x in get_scale_names ()]),
493506 scale_docs = get_scale_docs ().strip (),
0 commit comments