Skip to content

Commit bed8281

Browse files
timhoffmmeeseeksmachine
authored andcommitted
Backport PR #29404: DOC: scales - built in options and custom scale usefulness
1 parent 592650e commit bed8281

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

galleries/examples/scales/custom_scale.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55
Custom scale
66
============
77
8-
Create a custom scale, by implementing the scaling use for latitude data in a
9-
Mercator Projection.
8+
Custom scales can be created in two ways
9+
10+
#. For simple cases, use `~.scale.FuncScale` and the ``'function'`` option of
11+
`~.Axes.set_xscale` and `~.Axes.set_yscale`. See the last example in
12+
:doc:`/gallery/scales/scales`.
13+
14+
#. Create a custom scale class such as the one in this example, which implements
15+
the scaling use for latitude data in a Mercator Projection. This more complicated
16+
approach is useful when
17+
18+
* You are making special use of the `.Transform` class, such as the special
19+
handling of values beyond the threshold in ``MercatorLatitudeTransform``
20+
below.
21+
22+
* You want to override the default locators and formatters for the axis
23+
(``set_default_locators_and_formatters`` below).
24+
25+
* You want to limit the range of the the axis (``limit_range_for_scale`` below).
1026
11-
Unless you are making special use of the `.Transform` class, you probably
12-
don't need to use this verbose method, and instead can use `~.scale.FuncScale`
13-
and the ``'function'`` option of `~.Axes.set_xscale` and `~.Axes.set_yscale`.
14-
See the last example in :doc:`/gallery/scales/scales`.
1527
"""
1628

1729
import numpy as np

lib/matplotlib/axis.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -777,26 +777,15 @@ def _set_axes_scale(self, value, **kwargs):
777777
778778
Parameters
779779
----------
780-
value : {"linear", "log", "symlog", "logit", ...} or `.ScaleBase`
781-
The axis scale type to apply.
780+
value : str or `.ScaleBase`
781+
The axis scale type to apply. Valid string values are the names of scale
782+
classes ("linear", "log", "function",...). These may be the names of any
783+
of the :ref:`built-in scales<builtin_scales>` or of any custom scales
784+
registered using `matplotlib.scale.register_scale`.
782785
783786
**kwargs
784-
Different keyword arguments are accepted, depending on the scale.
785-
See the respective class keyword arguments:
786-
787-
- `matplotlib.scale.LinearScale`
788-
- `matplotlib.scale.LogScale`
789-
- `matplotlib.scale.SymmetricalLogScale`
790-
- `matplotlib.scale.LogitScale`
791-
- `matplotlib.scale.FuncScale`
792-
- `matplotlib.scale.AsinhScale`
793-
794-
Notes
795-
-----
796-
By default, Matplotlib supports the above-mentioned scales.
797-
Additionally, custom scales may be registered using
798-
`matplotlib.scale.register_scale`. These scales can then also
799-
be used here.
787+
If *value* is a string, keywords are passed to the instantiation method of
788+
the respective class.
800789
"""
801790
name = self._get_axis_name()
802791
old_default_lims = (self.get_major_locator()

lib/matplotlib/scale.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
44
The mapping is implemented through `.Transform` subclasses.
55
6-
The following scales are builtin:
6+
The following scales are built-in:
7+
8+
.. _builtin_scales:
79
810
============= ===================== ================================ =================================
911
Name Class Transform Inverted transform

0 commit comments

Comments
 (0)