Skip to content

Commit 05a02ae

Browse files
authored
Merge pull request matplotlib#19926 from anntzer/spd
Move custom scales/custom projections docs to module docstrings.
2 parents 3a316b9 + 768ce70 commit 05a02ae

File tree

6 files changed

+79
-147
lines changed

6 files changed

+79
-147
lines changed

doc/api/prev_api_changes/api_changes_1.2.x.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Changes in 1.2.x
6666

6767
This change means that third party objects can expose themselves as
6868
Matplotlib axes by providing a ``_as_mpl_axes`` method. See
69-
:ref:`adding-new-scales` for more detail.
69+
:mod:`matplotlib.projections` for more detail.
7070

7171
* A new keyword *extendfrac* in :meth:`~matplotlib.pyplot.colorbar` and
7272
:class:`~matplotlib.colorbar.ColorbarBase` allows one to control the size of

doc/devel/add_new_projection.rst

Lines changed: 0 additions & 129 deletions
This file was deleted.

doc/devel/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ process or how to fix something feel free to ask on `gitter
3636
development_setup.rst
3737
testing.rst
3838
documenting_mpl.rst
39-
add_new_projection.rst
4039
gitwash/index.rst
4140
coding_guide.rst
4241
release_guide.rst

lib/matplotlib/projections/__init__.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1+
"""
2+
Non-separable transforms that map from data space to screen space.
3+
4+
Projections are defined as `~.axes.Axes` subclasses. They include the
5+
following elements:
6+
7+
- A transformation from data coordinates into display coordinates.
8+
9+
- An inverse of that transformation. This is used, for example, to convert
10+
mouse positions from screen space back into data space.
11+
12+
- Transformations for the gridlines, ticks and ticklabels. Custom projections
13+
will often need to place these elements in special locations, and Matplotlib
14+
has a facility to help with doing so.
15+
16+
- Setting up default values (overriding `~.axes.Axes.cla`), since the defaults
17+
for a rectilinear axes may not be appropriate.
18+
19+
- Defining the shape of the axes, for example, an elliptical axes, that will be
20+
used to draw the background of the plot and for clipping any data elements.
21+
22+
- Defining custom locators and formatters for the projection. For example, in
23+
a geographic projection, it may be more convenient to display the grid in
24+
degrees, even if the data is in radians.
25+
26+
- Set up interactive panning and zooming. This is left as an "advanced"
27+
feature left to the reader, but there is an example of this for polar plots
28+
in `matplotlib.projections.polar`.
29+
30+
- Any additional methods for additional convenience or features.
31+
32+
Once the projection axes is defined, it can be used in one of two ways:
33+
34+
- By defining the class attribute ``name``, the projection axes can be
35+
registered with `matplotlib.projections.register_projection` and subsequently
36+
simply invoked by name::
37+
38+
fig.add_subplot(projection="my_proj_name")
39+
40+
- For more complex, parameterisable projections, a generic "projection" object
41+
may be defined which includes the method ``_as_mpl_axes``. ``_as_mpl_axes``
42+
should take no arguments and return the projection's axes subclass and a
43+
dictionary of additional arguments to pass to the subclass' ``__init__``
44+
method. Subsequently a parameterised projection can be initialised with::
45+
46+
fig.add_subplot(projection=MyProjection(param1=param1_value))
47+
48+
where MyProjection is an object which implements a ``_as_mpl_axes`` method.
49+
50+
A full-fledged and heavily annotated example is in
51+
:doc:`/gallery/misc/custom_projection`. The polar plot functionality in
52+
`matplotlib.projections.polar` may also be of interest.
53+
"""
54+
155
from .. import axes, docstring
256
from .geo import AitoffAxes, HammerAxes, LambertAxes, MollweideAxes
357
from .polar import PolarAxes

lib/matplotlib/scale.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
"""
22
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.
3+
They are defined as subclasses of `ScaleBase`.
64
75
See also `.axes.Axes.set_xscale` and the scales examples in the documentation.
6+
7+
See :doc:`/gallery/scales/custom_scale` for a full example of defining a custom
8+
scale.
9+
10+
Matplotlib also supports non-separable transformations that operate on both
11+
`~.axis.Axis` at the same time. They are known as projections, and defined in
12+
`matplotlib.projections`.
813
"""
914

1015
import inspect
@@ -28,16 +33,20 @@ class ScaleBase:
2833
2934
Scales are separable transformations, working on a single dimension.
3035
31-
Any subclasses will want to override:
32-
33-
- :attr:`name`
34-
- :meth:`get_transform`
35-
- :meth:`set_default_locators_and_formatters`
36-
37-
And optionally:
38-
39-
- :meth:`limit_range_for_scale`
40-
36+
Subclasses should override
37+
38+
:attr:`name`
39+
The scale's name.
40+
:meth:`get_transform`
41+
A method returning a `.Transform`, which converts data coordinates to
42+
scaled coordinates. This transform should be invertible, so that e.g.
43+
mouse positions can be converted back to data coordinates.
44+
:meth:`set_default_locators_and_formatters`
45+
A method that sets default locators and formatters for an `~.axis.Axis`
46+
that uses this scale.
47+
:meth:`limit_range_for_scale`
48+
An optional method that "fixes" the axis range to acceptable values,
49+
e.g. restricting log-scaled axes to positive values.
4150
"""
4251

4352
def __init__(self, axis):
@@ -56,8 +65,7 @@ def __init__(self, axis):
5665

5766
def get_transform(self):
5867
"""
59-
Return the :class:`~matplotlib.transforms.Transform` object
60-
associated with this scale.
68+
Return the `.Transform` object associated with this scale.
6169
"""
6270
raise NotImplementedError()
6371

tutorials/introductory/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,5 @@ def f(t):
461461
plt.show()
462462

463463
###############################################################################
464-
# It is also possible to add your own scale, see :ref:`adding-new-scales` for
464+
# It is also possible to add your own scale, see `matplotlib.scale` for
465465
# details.

0 commit comments

Comments
 (0)