Skip to content

Commit a9875dc

Browse files
committed
Cleanup of scales docs
1 parent 44728f1 commit a9875dc

File tree

2 files changed

+86
-79
lines changed

2 files changed

+86
-79
lines changed

lib/matplotlib/scale.py

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
import inspect
211
import textwrap
312

@@ -20,12 +29,14 @@ class ScaleBase:
2029
2130
Any subclasses will want to override:
2231
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`
2635
2736
And optionally:
28-
- :meth:`limit_range_for_scale`
37+
38+
- :meth:`limit_range_for_scale`
39+
2940
"""
3041

3142
def __init__(self, axis, **kwargs):
@@ -51,9 +62,8 @@ def get_transform(self):
5162

5263
def set_default_locators_and_formatters(self, axis):
5364
"""
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.
5767
"""
5868
raise NotImplementedError()
5969

@@ -63,7 +73,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
6373
domain supported by this scale.
6474
6575
*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.
6777
"""
6878
return vmin, vmax
6979

@@ -84,10 +94,7 @@ def __init__(self, axis, **kwargs):
8494
super().__init__(axis, **kwargs)
8595

8696
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
9198
axis.set_major_locator(AutoLocator())
9299
axis.set_major_formatter(ScalarFormatter())
93100
axis.set_minor_formatter(NullFormatter())
@@ -100,8 +107,8 @@ def set_default_locators_and_formatters(self, axis):
100107

101108
def get_transform(self):
102109
"""
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`.
105112
"""
106113
return IdentityTransform()
107114

@@ -157,8 +164,8 @@ def __init__(self, axis, functions):
157164
"""
158165
Parameters
159166
----------
160-
axis: the axis for the scale
161-
167+
axis : `matplotlib.axis.Axis`
168+
The axis for the scale.
162169
functions : (callable, callable)
163170
two-tuple of the forward and inverse functions for the scale.
164171
The forward function must be monotonic.
@@ -172,16 +179,11 @@ def forward(values: array-like) -> array-like
172179
self._transform = transform
173180

174181
def get_transform(self):
175-
"""
176-
The transform for arbitrary scaling
177-
"""
182+
"""Return the `.FuncTransform` associated with this scale."""
178183
return self._transform
179184

180185
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
185187
axis.set_major_locator(AutoLocator())
186188
axis.set_major_formatter(ScalarFormatter())
187189
axis.set_minor_formatter(NullFormatter())
@@ -354,18 +356,17 @@ class LogScale(ScaleBase):
354356

355357
def __init__(self, axis, **kwargs):
356358
"""
357-
*basex*/*basey*:
359+
Parameters
360+
----------
361+
basex, basey : float
358362
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
365368
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]``
369370
will place 8 logarithmically spaced minor ticks between
370371
each major tick.
371372
"""
@@ -397,10 +398,7 @@ def base(self):
397398
return self._transform.base
398399

399400
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
404402
axis.set_major_locator(LogLocator(self.base))
405403
axis.set_major_formatter(LogFormatterSciNotation(self.base))
406404
axis.set_minor_locator(LogLocator(self.base, self.subs))
@@ -409,10 +407,7 @@ def set_default_locators_and_formatters(self, axis):
409407
labelOnlyBase=(self.subs is not None)))
410408

411409
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."""
416411
return self._transform
417412

418413
def limit_range_for_scale(self, vmin, vmax, minpos):
@@ -438,8 +433,8 @@ def __init__(self, axis, functions, base=10):
438433
"""
439434
Parameters
440435
----------
441-
axis: the axis for the scale
442-
436+
axis : `matplotlib.axis.Axis`
437+
The axis for the scale.
443438
functions : (callable, callable)
444439
two-tuple of the forward and inverse functions for the scale.
445440
The forward function must be monotonic.
@@ -461,9 +456,7 @@ def base(self):
461456
return self._transform._b.base # Base of the LogTransform.
462457

463458
def get_transform(self):
464-
"""
465-
The transform for arbitrary scaling
466-
"""
459+
"""Return the `.Transform` associated with this scale."""
467460
return self._transform
468461

469462

@@ -592,20 +585,15 @@ def __init__(self, axis, **kwargs):
592585
self.subs = subs
593586

594587
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
599589
axis.set_major_locator(SymmetricalLogLocator(self.get_transform()))
600590
axis.set_major_formatter(LogFormatterSciNotation(self.base))
601591
axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(),
602592
self.subs))
603593
axis.set_minor_formatter(NullFormatter())
604594

605595
def get_transform(self):
606-
"""
607-
Return a :class:`SymmetricalLogTransform` instance.
608-
"""
596+
"""Return the `.SymmetricalLogTransform` associated with this scale."""
609597
return self._transform
610598

611599

@@ -669,19 +657,22 @@ class LogitScale(ScaleBase):
669657

670658
def __init__(self, axis, nonpos='mask'):
671659
"""
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.
675667
"""
676668
self._transform = LogitTransform(nonpos)
677669

678670
def get_transform(self):
679-
"""
680-
Return a :class:`LogitTransform` instance.
681-
"""
671+
"""Return the `.LogitTransform` associated with this scale."""
682672
return self._transform
683673

684674
def set_default_locators_and_formatters(self, axis):
675+
# docstring inherited
685676
# ..., 0.01, 0.1, 0.5, 0.9, 0.99, ...
686677
axis.set_major_locator(LogitLocator())
687678
axis.set_major_formatter(LogitFormatter())
@@ -709,6 +700,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
709700

710701

711702
def get_scale_names():
703+
"""Return the names of the available scales."""
712704
return sorted(_scale_mapping)
713705

714706

@@ -719,22 +711,25 @@ def scale_factory(scale, axis, **kwargs):
719711
Parameters
720712
----------
721713
scale : {%(names)s}
722-
axis : Axis
714+
axis : `matplotlib.axis.Axis`
723715
"""
724716
scale = scale.lower()
725717
cbook._check_in_list(_scale_mapping, scale=scale)
726718
return _scale_mapping[scale](axis, **kwargs)
727719

728720
if scale_factory.__doc__:
729721
scale_factory.__doc__ = scale_factory.__doc__ % {
730-
"names": ", ".join(get_scale_names())}
722+
"names": ", ".join(map(repr, get_scale_names())}
731723

732724

733725
def register_scale(scale_class):
734726
"""
735727
Register a new kind of scale.
736728
737-
*scale_class* must be a subclass of :class:`ScaleBase`.
729+
Parameters
730+
----------
731+
scale_class : subclass of `ScaleBase`
732+
The scale to register.
738733
"""
739734
_scale_mapping[scale_class.name] = scale_class
740735

lib/matplotlib/transforms.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,18 +1188,18 @@ class Transform(TransformNode):
11881188
Subclasses of this class should override the following members (at
11891189
minimum):
11901190
1191-
- :attr:`input_dims`
1192-
- :attr:`output_dims`
1193-
- :meth:`transform`
1194-
- :attr:`is_separable`
1195-
- :attr:`has_inverse`
1196-
- :meth:`inverted` (if :attr:`has_inverse` is True)
1191+
- :attr:`input_dims`
1192+
- :attr:`output_dims`
1193+
- :meth:`transform`
1194+
- :attr:`is_separable`
1195+
- :attr:`has_inverse`
1196+
- :meth:`inverted` (if :attr:`has_inverse` is True)
11971197
11981198
If the transform needs to do something non-standard with
11991199
:class:`matplotlib.path.Path` objects, such as adding curves
12001200
where there were once line segments, it should override:
12011201
1202-
- :meth:`transform_path`
1202+
- :meth:`transform_path`
12031203
"""
12041204
input_dims = None
12051205
"""
@@ -1403,11 +1403,17 @@ def transform_affine(self, values):
14031403
affine transformations, this is equivalent to
14041404
``transform(values)``.
14051405
1406-
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1407-
returns a numpy array of shape (N x :attr:`output_dims`).
1406+
Parameters
1407+
----------
1408+
values : array
1409+
The input values as numpy array of length :attr:`input_dims` or
1410+
shape (N x :attr:`input_dims`).
14081411
1409-
Alternatively, accepts a numpy array of length :attr:`input_dims`
1410-
and returns a numpy array of length :attr:`output_dims`.
1412+
Returns
1413+
-------
1414+
values : array
1415+
The output values as numpy array of length :attr:`input_dims` or
1416+
shape (N x :attr:`output_dims`), depending on the input.
14111417
"""
14121418
return self.get_affine().transform(values)
14131419

@@ -1422,11 +1428,17 @@ def transform_non_affine(self, values):
14221428
``transform(values)``. In affine transformations, this is
14231429
always a no-op.
14241430
1425-
Accepts a numpy array of shape (N x :attr:`input_dims`) and
1426-
returns a numpy array of shape (N x :attr:`output_dims`).
1431+
Parameters
1432+
----------
1433+
values : array
1434+
The input values as numpy array of length :attr:`input_dims` or
1435+
shape (N x :attr:`input_dims`).
14271436
1428-
Alternatively, accepts a numpy array of length :attr:`input_dims`
1429-
and returns a numpy array of length :attr:`output_dims`.
1437+
Returns
1438+
-------
1439+
values : array
1440+
The output values as numpy array of length :attr:`input_dims` or
1441+
shape (N x :attr:`output_dims`), depending on the input.
14301442
"""
14311443
return values
14321444

@@ -1558,11 +1570,11 @@ def inverted(self):
15581570
"""
15591571
Return the corresponding inverse transformation.
15601572
1573+
It holds ``x == self.inverted().transform(self.transform(x))``.
1574+
15611575
The return value of this method should be treated as
15621576
temporary. An update to *self* does not cause a corresponding
15631577
update to its inverted copy.
1564-
1565-
``x === self.inverted().transform(self.transform(x))``
15661578
"""
15671579
raise NotImplementedError()
15681580

0 commit comments

Comments
 (0)