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,12 @@ 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."""
183
+ # docstring inherited
178
184
return self ._transform
179
185
180
186
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
- """
187
+ # docstring inherited
185
188
axis .set_major_locator (AutoLocator ())
186
189
axis .set_major_formatter (ScalarFormatter ())
187
190
axis .set_minor_formatter (NullFormatter ())
@@ -354,18 +357,17 @@ class LogScale(ScaleBase):
354
357
355
358
def __init__ (self , axis , ** kwargs ):
356
359
"""
357
- *basex*/*basey*:
360
+ Parameters
361
+ ----------
362
+ basex, basey : float
358
363
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*:
364
+ nonposx, nonposy : {'mask', 'clip'}
365
+ Determines the behavior for non-positive values. They can either
366
+ be masked as invalid, or clipped to a number very small positive
367
+ number.
368
+ subsx, subsy : sequence of int
365
369
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
-
370
+ For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]``
369
371
will place 8 logarithmically spaced minor ticks between
370
372
each major tick.
371
373
"""
@@ -397,10 +399,7 @@ def base(self):
397
399
return self ._transform .base
398
400
399
401
def set_default_locators_and_formatters (self , axis ):
400
- """
401
- Set the locators and formatters to specialized versions for
402
- log scaling.
403
- """
402
+ # docstring inherited
404
403
axis .set_major_locator (LogLocator (self .base ))
405
404
axis .set_major_formatter (LogFormatterSciNotation (self .base ))
406
405
axis .set_minor_locator (LogLocator (self .base , self .subs ))
@@ -409,10 +408,7 @@ def set_default_locators_and_formatters(self, axis):
409
408
labelOnlyBase = (self .subs is not None )))
410
409
411
410
def get_transform (self ):
412
- """
413
- Return a :class:`~matplotlib.transforms.Transform` instance
414
- appropriate for the given logarithm base.
415
- """
411
+ """Return the `.LogTransform` associated with this scale."""
416
412
return self ._transform
417
413
418
414
def limit_range_for_scale (self , vmin , vmax , minpos ):
@@ -438,8 +434,8 @@ def __init__(self, axis, functions, base=10):
438
434
"""
439
435
Parameters
440
436
----------
441
- axis: the axis for the scale
442
-
437
+ axis : `matplotlib. axis.Axis`
438
+ The axis for the scale.
443
439
functions : (callable, callable)
444
440
two-tuple of the forward and inverse functions for the scale.
445
441
The forward function must be monotonic.
@@ -461,9 +457,7 @@ def base(self):
461
457
return self ._transform ._b .base # Base of the LogTransform.
462
458
463
459
def get_transform (self ):
464
- """
465
- The transform for arbitrary scaling
466
- """
460
+ """Return the `.Transform` associated with this scale."""
467
461
return self ._transform
468
462
469
463
@@ -592,20 +586,15 @@ def __init__(self, axis, **kwargs):
592
586
self .subs = subs
593
587
594
588
def set_default_locators_and_formatters (self , axis ):
595
- """
596
- Set the locators and formatters to specialized versions for
597
- symmetrical log scaling.
598
- """
589
+ # docstring inherited
599
590
axis .set_major_locator (SymmetricalLogLocator (self .get_transform ()))
600
591
axis .set_major_formatter (LogFormatterSciNotation (self .base ))
601
592
axis .set_minor_locator (SymmetricalLogLocator (self .get_transform (),
602
593
self .subs ))
603
594
axis .set_minor_formatter (NullFormatter ())
604
595
605
596
def get_transform (self ):
606
- """
607
- Return a :class:`SymmetricalLogTransform` instance.
608
- """
597
+ """Return the `.SymmetricalLogTransform` associated with this scale."""
609
598
return self ._transform
610
599
611
600
@@ -669,19 +658,22 @@ class LogitScale(ScaleBase):
669
658
670
659
def __init__ (self , axis , nonpos = 'mask' ):
671
660
"""
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
661
+ Parameters
662
+ ----------
663
+ axis : `matplotlib.axis.Axis`
664
+ Currently used.
665
+ nonpos : {'mask', 'clip'}
666
+ Determines the behavior for values beyond ]0, 1[. They can either
667
+ be masked as invalid, or clipped to a number very close to 0 or 1.
675
668
"""
676
669
self ._transform = LogitTransform (nonpos )
677
670
678
671
def get_transform (self ):
679
- """
680
- Return a :class:`LogitTransform` instance.
681
- """
672
+ """Return the `.LogitTransform` associated with this scale."""
682
673
return self ._transform
683
674
684
675
def set_default_locators_and_formatters (self , axis ):
676
+ # docstring inherited
685
677
# ..., 0.01, 0.1, 0.5, 0.9, 0.99, ...
686
678
axis .set_major_locator (LogitLocator ())
687
679
axis .set_major_formatter (LogitFormatter ())
@@ -709,6 +701,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
709
701
710
702
711
703
def get_scale_names ():
704
+ """Return the names of the available scales."""
712
705
return sorted (_scale_mapping )
713
706
714
707
@@ -719,22 +712,25 @@ def scale_factory(scale, axis, **kwargs):
719
712
Parameters
720
713
----------
721
714
scale : {%(names)s}
722
- axis : Axis
715
+ axis : `matplotlib.axis. Axis`
723
716
"""
724
717
scale = scale .lower ()
725
718
cbook ._check_in_list (_scale_mapping , scale = scale )
726
719
return _scale_mapping [scale ](axis , ** kwargs )
727
720
728
721
if scale_factory .__doc__ :
729
722
scale_factory .__doc__ = scale_factory .__doc__ % {
730
- "names" : ", " .join (get_scale_names ())}
723
+ "names" : ", " .join (f"' { s } '" for s in get_scale_names ())}
731
724
732
725
733
726
def register_scale (scale_class ):
734
727
"""
735
728
Register a new kind of scale.
736
729
737
- *scale_class* must be a subclass of :class:`ScaleBase`.
730
+ Parameters
731
+ ----------
732
+ scale_class : subclass of `ScaleBase`
733
+ The scale to register.
738
734
"""
739
735
_scale_mapping [scale_class .name ] = scale_class
740
736
0 commit comments