1
+ """
2
+ Scales define the distribution of data values on an axis, e.g. a log scaling.
3
+
4
+ They are attached to an `~.axis.Axis` and hold a `.Transform`, which is
5
+ responsible for the actual data transformation.
6
+
7
+ See also `.axes.Axes.set_xscale` and the scales examples in the documentation.
8
+ """
9
+
1
10
import inspect
2
11
import textwrap
3
12
@@ -20,12 +29,14 @@ class ScaleBase:
20
29
21
30
Any subclasses will want to override:
22
31
23
- - :attr:`name`
24
- - :meth:`get_transform`
25
- - :meth:`set_default_locators_and_formatters`
32
+ - :attr:`name`
33
+ - :meth:`get_transform`
34
+ - :meth:`set_default_locators_and_formatters`
26
35
27
36
And optionally:
28
- - :meth:`limit_range_for_scale`
37
+
38
+ - :meth:`limit_range_for_scale`
39
+
29
40
"""
30
41
31
42
def __init__ (self , axis , ** kwargs ):
@@ -51,9 +62,8 @@ def get_transform(self):
51
62
52
63
def set_default_locators_and_formatters (self , axis ):
53
64
"""
54
- Set the :class:`~matplotlib.ticker.Locator` and
55
- :class:`~matplotlib.ticker.Formatter` objects on the given
56
- axis to match this scale.
65
+ Set the locators and formatters of *axis* to instances suitable for
66
+ this scale.
57
67
"""
58
68
raise NotImplementedError ()
59
69
@@ -63,7 +73,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
63
73
domain supported by this scale.
64
74
65
75
*minpos* should be the minimum positive value in the data.
66
- This is used by log scales to determine a minimum value.
76
+ This is used by log scales to determine a minimum value.
67
77
"""
68
78
return vmin , vmax
69
79
@@ -84,10 +94,7 @@ def __init__(self, axis, **kwargs):
84
94
super ().__init__ (axis , ** kwargs )
85
95
86
96
def set_default_locators_and_formatters (self , axis ):
87
- """
88
- Set the locators and formatters to reasonable defaults for
89
- linear scaling.
90
- """
97
+ # docstring inherited
91
98
axis .set_major_locator (AutoLocator ())
92
99
axis .set_major_formatter (ScalarFormatter ())
93
100
axis .set_minor_formatter (NullFormatter ())
@@ -100,8 +107,8 @@ def set_default_locators_and_formatters(self, axis):
100
107
101
108
def get_transform (self ):
102
109
"""
103
- The transform for linear scaling is just the
104
- :class: `~matplotlib.transforms.IdentityTransform`.
110
+ Return the transform for linear scaling, which is just the
111
+ `~matplotlib.transforms.IdentityTransform`.
105
112
"""
106
113
return IdentityTransform ()
107
114
@@ -157,8 +164,8 @@ def __init__(self, axis, functions):
157
164
"""
158
165
Parameters
159
166
----------
160
- axis: the axis for the scale
161
-
167
+ axis : `matplotlib. axis.Axis`
168
+ The axis for the scale.
162
169
functions : (callable, callable)
163
170
two-tuple of the forward and inverse functions for the scale.
164
171
The forward function must be monotonic.
@@ -172,16 +179,11 @@ def forward(values: array-like) -> array-like
172
179
self ._transform = transform
173
180
174
181
def get_transform (self ):
175
- """
176
- The transform for arbitrary scaling
177
- """
182
+ """Return the `.FuncTransform` associated with this scale."""
178
183
return self ._transform
179
184
180
185
def set_default_locators_and_formatters (self , axis ):
181
- """
182
- Set the locators and formatters to the same defaults as the
183
- linear scale.
184
- """
186
+ # docstring inherited
185
187
axis .set_major_locator (AutoLocator ())
186
188
axis .set_major_formatter (ScalarFormatter ())
187
189
axis .set_minor_formatter (NullFormatter ())
@@ -354,18 +356,17 @@ class LogScale(ScaleBase):
354
356
355
357
def __init__ (self , axis , ** kwargs ):
356
358
"""
357
- *basex*/*basey*:
359
+ Parameters
360
+ ----------
361
+ basex, basey : float
358
362
The base of the logarithm
359
-
360
- *nonposx*/*nonposy*: {'mask', 'clip'}
361
- non-positive values in *x* or *y* can be masked as
362
- invalid, or clipped to a very small positive number
363
-
364
- *subsx*/*subsy*:
363
+ nonposx, nonposy : {'mask', 'clip'}
364
+ Determines the behavior for non-positive values. They can either
365
+ be masked as invalid, or clipped to a number very small positive
366
+ number.
367
+ subsx, subsy : sequence of int
365
368
Where to place the subticks between each major tick.
366
- Should be a sequence of integers. For example, in a log10
367
- scale: ``[2, 3, 4, 5, 6, 7, 8, 9]``
368
-
369
+ For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]``
369
370
will place 8 logarithmically spaced minor ticks between
370
371
each major tick.
371
372
"""
@@ -397,10 +398,7 @@ def base(self):
397
398
return self ._transform .base
398
399
399
400
def set_default_locators_and_formatters (self , axis ):
400
- """
401
- Set the locators and formatters to specialized versions for
402
- log scaling.
403
- """
401
+ # docstring inherited
404
402
axis .set_major_locator (LogLocator (self .base ))
405
403
axis .set_major_formatter (LogFormatterSciNotation (self .base ))
406
404
axis .set_minor_locator (LogLocator (self .base , self .subs ))
@@ -409,10 +407,7 @@ def set_default_locators_and_formatters(self, axis):
409
407
labelOnlyBase = (self .subs is not None )))
410
408
411
409
def get_transform (self ):
412
- """
413
- Return a :class:`~matplotlib.transforms.Transform` instance
414
- appropriate for the given logarithm base.
415
- """
410
+ """Return the `.LogTransform` associated with this scale."""
416
411
return self ._transform
417
412
418
413
def limit_range_for_scale (self , vmin , vmax , minpos ):
@@ -438,8 +433,8 @@ def __init__(self, axis, functions, base=10):
438
433
"""
439
434
Parameters
440
435
----------
441
- axis: the axis for the scale
442
-
436
+ axis : `matplotlib. axis.Axis`
437
+ The axis for the scale.
443
438
functions : (callable, callable)
444
439
two-tuple of the forward and inverse functions for the scale.
445
440
The forward function must be monotonic.
@@ -461,9 +456,7 @@ def base(self):
461
456
return self ._transform ._b .base # Base of the LogTransform.
462
457
463
458
def get_transform (self ):
464
- """
465
- The transform for arbitrary scaling
466
- """
459
+ """Return the `.Transform` associated with this scale."""
467
460
return self ._transform
468
461
469
462
@@ -592,20 +585,15 @@ def __init__(self, axis, **kwargs):
592
585
self .subs = subs
593
586
594
587
def set_default_locators_and_formatters (self , axis ):
595
- """
596
- Set the locators and formatters to specialized versions for
597
- symmetrical log scaling.
598
- """
588
+ # docstring inherited
599
589
axis .set_major_locator (SymmetricalLogLocator (self .get_transform ()))
600
590
axis .set_major_formatter (LogFormatterSciNotation (self .base ))
601
591
axis .set_minor_locator (SymmetricalLogLocator (self .get_transform (),
602
592
self .subs ))
603
593
axis .set_minor_formatter (NullFormatter ())
604
594
605
595
def get_transform (self ):
606
- """
607
- Return a :class:`SymmetricalLogTransform` instance.
608
- """
596
+ """Return the `.SymmetricalLogTransform` associated with this scale."""
609
597
return self ._transform
610
598
611
599
@@ -669,19 +657,22 @@ class LogitScale(ScaleBase):
669
657
670
658
def __init__ (self , axis , nonpos = 'mask' ):
671
659
"""
672
- *nonpos*: {'mask', 'clip'}
673
- values beyond ]0, 1[ can be masked as invalid, or clipped to a number
674
- very close to 0 or 1
660
+ Parameters
661
+ ----------
662
+ axis : `matplotlib.axis.Axis`
663
+ Currently unused.
664
+ nonpos : {'mask', 'clip'}
665
+ Determines the behavior for values beyond ]0, 1[. They can either
666
+ be masked as invalid, or clipped to a number very close to 0 or 1.
675
667
"""
676
668
self ._transform = LogitTransform (nonpos )
677
669
678
670
def get_transform (self ):
679
- """
680
- Return a :class:`LogitTransform` instance.
681
- """
671
+ """Return the `.LogitTransform` associated with this scale."""
682
672
return self ._transform
683
673
684
674
def set_default_locators_and_formatters (self , axis ):
675
+ # docstring inherited
685
676
# ..., 0.01, 0.1, 0.5, 0.9, 0.99, ...
686
677
axis .set_major_locator (LogitLocator ())
687
678
axis .set_major_formatter (LogitFormatter ())
@@ -709,6 +700,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
709
700
710
701
711
702
def get_scale_names ():
703
+ """Return the names of the available scales."""
712
704
return sorted (_scale_mapping )
713
705
714
706
@@ -719,22 +711,25 @@ def scale_factory(scale, axis, **kwargs):
719
711
Parameters
720
712
----------
721
713
scale : {%(names)s}
722
- axis : Axis
714
+ axis : `matplotlib.axis. Axis`
723
715
"""
724
716
scale = scale .lower ()
725
717
cbook ._check_in_list (_scale_mapping , scale = scale )
726
718
return _scale_mapping [scale ](axis , ** kwargs )
727
719
728
720
if scale_factory .__doc__ :
729
721
scale_factory .__doc__ = scale_factory .__doc__ % {
730
- "names" : ", " .join (get_scale_names ())}
722
+ "names" : ", " .join (map ( repr , get_scale_names ())}
731
723
732
724
733
725
def register_scale (scale_class ):
734
726
"""
735
727
Register a new kind of scale.
736
728
737
- *scale_class* must be a subclass of :class:`ScaleBase`.
729
+ Parameters
730
+ ----------
731
+ scale_class : subclass of `ScaleBase`
732
+ The scale to register.
738
733
"""
739
734
_scale_mapping [scale_class .name ] = scale_class
740
735
0 commit comments