Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddc5bdb

Browse files
Merge branch 'matplotlib:main' into deprecated_api
2 parents d89567a + e237bbd commit ddc5bdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+509
-408
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ repos:
5555
- id: rstcheck
5656
additional_dependencies:
5757
- sphinx>=1.8.1
58+
- tomli

ci/mypy-stubtest-allowlist.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ matplotlib.ticker.LogitLocator.nonsingular
3232
matplotlib.backend_bases._Mode.__new__
3333
matplotlib.units.Number.__hash__
3434

35-
# Property read-write vs read-only weirdness, fix if possible
36-
matplotlib.offsetbox.DraggableBase.canvas
37-
matplotlib.offsetbox.DraggableBase.cids
38-
matplotlib.transforms.BboxTransform.is_separable
39-
matplotlib.transforms.BboxTransformFrom.is_separable
40-
matplotlib.transforms.BboxTransformTo.is_separable
41-
matplotlib.transforms.BlendedAffine2D.is_separable
42-
matplotlib.transforms.CompositeGenericTransform.is_separable
43-
matplotlib.transforms.TransformWrapper.input_dims
44-
matplotlib.transforms.TransformWrapper.is_separable
45-
matplotlib.transforms.TransformWrapper.output_dims
46-
4735
# 3.6 Pending deprecations
4836
matplotlib.figure.Figure.set_constrained_layout
4937
matplotlib.figure.Figure.set_constrained_layout_pads
@@ -52,7 +40,6 @@ matplotlib.figure.Figure.set_tight_layout
5240
# 3.7 deprecations
5341
matplotlib.cm.register_cmap
5442
matplotlib.cm.unregister_cmap
55-
matplotlib.collections.PolyCollection.span_where
5643

5744
# 3.8 deprecations
5845
matplotlib.cbook.get_sample_data
@@ -148,16 +135,10 @@ matplotlib.text.Text.set_weight
148135
matplotlib.axes._base._AxesBase.get_fc
149136
matplotlib.axes._base._AxesBase.set_fc
150137

151-
# Other dynamic python behaviors not type hinted
152-
matplotlib.rcsetup.defaultParams
153-
154138
# Maybe should be abstractmethods, required for subclasses, stubs define once
155139
matplotlib.tri.*TriInterpolator.__call__
156140
matplotlib.tri.*TriInterpolator.gradient
157141

158-
# Functionally a method call, but actually a class instance, type hinted as former
159-
matplotlib.rcsetup.validate_fillstyle
160-
161142
# TypeVar used only in type hints
162143
matplotlib.backend_bases.FigureCanvasBase._T
163144
matplotlib.backend_managers.ToolManager._T

doc/api/artist_api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Inheritance Diagrams
1212
====================
1313

14-
.. inheritance-diagram:: matplotlib.axes._axes.Axes matplotlib.axes._base._AxesBase matplotlib.axis.Axis matplotlib.axis.Tick matplotlib.axis.XAxis matplotlib.axis.XTick matplotlib.axis.YAxis matplotlib.axis.YTick matplotlib.collections.AsteriskPolygonCollection matplotlib.collections.BrokenBarHCollection matplotlib.collections.CircleCollection matplotlib.collections.Collection matplotlib.collections.EllipseCollection matplotlib.collections.EventCollection matplotlib.collections.LineCollection matplotlib.collections.PatchCollection matplotlib.collections.PathCollection matplotlib.collections.PolyCollection matplotlib.collections.QuadMesh matplotlib.collections.RegularPolyCollection matplotlib.collections.StarPolygonCollection matplotlib.collections.TriMesh matplotlib.collections._CollectionWithSizes matplotlib.contour.ClabelText matplotlib.contour.ContourSet matplotlib.contour.QuadContourSet matplotlib.figure.FigureBase matplotlib.figure.Figure matplotlib.figure.SubFigure matplotlib.image.AxesImage matplotlib.image.BboxImage matplotlib.image.FigureImage matplotlib.image.NonUniformImage matplotlib.image.PcolorImage matplotlib.image._ImageBase matplotlib.legend.Legend matplotlib.lines.Line2D matplotlib.offsetbox.AnchoredOffsetbox matplotlib.offsetbox.AnchoredText matplotlib.offsetbox.AnnotationBbox matplotlib.offsetbox.AuxTransformBox matplotlib.offsetbox.DrawingArea matplotlib.offsetbox.HPacker matplotlib.offsetbox.OffsetBox matplotlib.offsetbox.OffsetImage matplotlib.offsetbox.PackerBase matplotlib.offsetbox.PaddedBox matplotlib.offsetbox.TextArea matplotlib.offsetbox.VPacker matplotlib.patches.Annulus matplotlib.patches.Arc matplotlib.patches.Arrow matplotlib.patches.Circle matplotlib.patches.CirclePolygon matplotlib.patches.ConnectionPatch matplotlib.patches.Ellipse matplotlib.patches.FancyArrow matplotlib.patches.FancyArrowPatch matplotlib.patches.FancyBboxPatch matplotlib.patches.Patch matplotlib.patches.PathPatch matplotlib.patches.Polygon matplotlib.patches.Rectangle matplotlib.patches.RegularPolygon matplotlib.patches.Shadow matplotlib.patches.StepPatch matplotlib.patches.Wedge matplotlib.projections.geo.AitoffAxes matplotlib.projections.geo.GeoAxes matplotlib.projections.geo.HammerAxes matplotlib.projections.geo.LambertAxes matplotlib.projections.geo.MollweideAxes matplotlib.projections.polar.PolarAxes matplotlib.projections.polar.RadialAxis matplotlib.projections.polar.RadialTick matplotlib.projections.polar.ThetaAxis matplotlib.projections.polar.ThetaTick matplotlib.quiver.Barbs matplotlib.quiver.Quiver matplotlib.quiver.QuiverKey matplotlib.spines.Spine matplotlib.table.Cell matplotlib.table.Table matplotlib.text.Annotation matplotlib.text.Text matplotlib.tri.TriContourSet
14+
.. inheritance-diagram:: matplotlib.axes._axes.Axes matplotlib.axes._base._AxesBase matplotlib.axis.Axis matplotlib.axis.Tick matplotlib.axis.XAxis matplotlib.axis.XTick matplotlib.axis.YAxis matplotlib.axis.YTick matplotlib.collections.AsteriskPolygonCollection matplotlib.collections.CircleCollection matplotlib.collections.Collection matplotlib.collections.EllipseCollection matplotlib.collections.EventCollection matplotlib.collections.LineCollection matplotlib.collections.PatchCollection matplotlib.collections.PathCollection matplotlib.collections.PolyCollection matplotlib.collections.QuadMesh matplotlib.collections.RegularPolyCollection matplotlib.collections.StarPolygonCollection matplotlib.collections.TriMesh matplotlib.collections._CollectionWithSizes matplotlib.contour.ClabelText matplotlib.contour.ContourSet matplotlib.contour.QuadContourSet matplotlib.figure.FigureBase matplotlib.figure.Figure matplotlib.figure.SubFigure matplotlib.image.AxesImage matplotlib.image.BboxImage matplotlib.image.FigureImage matplotlib.image.NonUniformImage matplotlib.image.PcolorImage matplotlib.image._ImageBase matplotlib.legend.Legend matplotlib.lines.Line2D matplotlib.offsetbox.AnchoredOffsetbox matplotlib.offsetbox.AnchoredText matplotlib.offsetbox.AnnotationBbox matplotlib.offsetbox.AuxTransformBox matplotlib.offsetbox.DrawingArea matplotlib.offsetbox.HPacker matplotlib.offsetbox.OffsetBox matplotlib.offsetbox.OffsetImage matplotlib.offsetbox.PackerBase matplotlib.offsetbox.PaddedBox matplotlib.offsetbox.TextArea matplotlib.offsetbox.VPacker matplotlib.patches.Annulus matplotlib.patches.Arc matplotlib.patches.Arrow matplotlib.patches.Circle matplotlib.patches.CirclePolygon matplotlib.patches.ConnectionPatch matplotlib.patches.Ellipse matplotlib.patches.FancyArrow matplotlib.patches.FancyArrowPatch matplotlib.patches.FancyBboxPatch matplotlib.patches.Patch matplotlib.patches.PathPatch matplotlib.patches.Polygon matplotlib.patches.Rectangle matplotlib.patches.RegularPolygon matplotlib.patches.Shadow matplotlib.patches.StepPatch matplotlib.patches.Wedge matplotlib.projections.geo.AitoffAxes matplotlib.projections.geo.GeoAxes matplotlib.projections.geo.HammerAxes matplotlib.projections.geo.LambertAxes matplotlib.projections.geo.MollweideAxes matplotlib.projections.polar.PolarAxes matplotlib.projections.polar.RadialAxis matplotlib.projections.polar.RadialTick matplotlib.projections.polar.ThetaAxis matplotlib.projections.polar.ThetaTick matplotlib.quiver.Barbs matplotlib.quiver.Quiver matplotlib.quiver.QuiverKey matplotlib.spines.Spine matplotlib.table.Cell matplotlib.table.Table matplotlib.text.Annotation matplotlib.text.Text matplotlib.tri.TriContourSet
1515
:parts: 1
1616
:private-bases:
1717

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``axvspan`` and ``axhspan`` now return ``Rectangle``\s, not ``Polygons``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
This change allows using `~.Axes.axhspan` to draw an annulus on polar axes.
4+
5+
This change also affects other elements built via `~.Axes.axvspan` and
6+
`~.Axes.axhspan`, such as ``Slider.poly``.

doc/api/next_api_changes/removals/26852-OG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33

44
... of the `.dates` module are removed without replacements. These were
55
undocumented and not exported.
6+
7+
Julian dates in Matplotlib were calculated from a Julian date epoch: ``jdate =
8+
(date - np.datetime64(EPOCH)) / np.timedelta64(1, 'D')``. Conversely, a Julian
9+
date was converted to datetime as ``date = np.timedelta64(int(jdate * 24 *
10+
3600), 's') + np.datetime64(EPOCH)``. Matplotlib was using
11+
``EPOCH='-4713-11-24T12:00'`` so that 2000-01-01 at 12:00 is 2_451_545.0 (see
12+
<https://en.wikipedia.org/wiki/Julian_day>`).
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
``repeat``
2-
~~~~~~~~~~
3-
... of `.TimedAnimation` is removed without replacements.
4-
``save_count``
5-
~~~~~~~~~~~~~~
6-
... of `.FuncAnimation` is removed without replacements.
1+
``Animation`` attributes
2+
~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The attributes ``repeat`` of `.TimedAnimation` and subclasses and
5+
``save_count`` of `.FuncAnimation` are considered private and removed.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``collections.PolyCollection.span_where`` and ``collections.BrokenBarHCollection``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... removed as it was deprecated during 3.7. Use ``fill_between`` instead
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``Quiver.quiver_doc`` and ``Barbs.barbs_doc``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are removed. These are the doc-string and should not be accessible as a named class member.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``axhline`` and ``axhspan`` on polar axes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... now draw circles and circular arcs (`~.Axes.axhline`) or annuli and wedges
5+
(`~.Axes.axhspan`).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``axisartist`` can now be used together with standard ``Formatters``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... instead of being limited to axisartist-specific ones.

doc/users/prev_whats_new/whats_new_1.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Added size related functions to specialized `.Collection`\s
221221
Added the ``get_size`` and ``set_size`` functions to control the size of
222222
elements of specialized collections (
223223
:class:`~matplotlib.collections.AsteriskPolygonCollection`
224-
:class:`~matplotlib.collections.BrokenBarHCollection`
224+
``matplotlib.collections.BrokenBarHCollection``
225225
:class:`~matplotlib.collections.CircleCollection`
226226
:class:`~matplotlib.collections.PathCollection`
227227
:class:`~matplotlib.collections.PolyCollection`

galleries/examples/axes_grid1/demo_colorbar_with_axes_divider.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
2+
.. _demo-colorbar-with-axes-divider:
3+
24
=========================
35
Colorbar with AxesDivider
46
=========================
@@ -8,6 +10,10 @@
810
method of the `.AxesDivider` can then be used to create a new axes on a given
911
side ("top", "right", "bottom", or "left") of the original axes. This example
1012
uses `.append_axes` to add colorbars next to axes.
13+
14+
Users should consider simply passing the main axes to the *ax* keyword argument of
15+
`~.Figure.colorbar` instead of creating a locatable axes manually like this.
16+
See :ref:`colorbar_placement`.
1117
"""
1218

1319
import matplotlib.pyplot as plt

galleries/examples/axes_grid1/demo_colorbar_with_inset_locator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
"""
2+
.. _demo-colorbar-with-inset-locator:
3+
24
==============================================================
35
Controlling the position and size of colorbars with Inset Axes
46
==============================================================
57
6-
This example shows how to control the position, height, and width of
7-
colorbars using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
8+
This example shows how to control the position, height, and width of colorbars
9+
using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
810
911
Inset axes placement is controlled as for legends: either by providing a *loc*
1012
option ("upper right", "best", ...), or by providing a locator with respect to
1113
the parent bbox. Parameters such as *bbox_to_anchor* and *borderpad* likewise
1214
work in the same way, and are also demonstrated here.
15+
16+
Users should consider using `.Axes.inset_axes` instead (see
17+
:ref:`colorbar_placement`).
18+
1319
"""
1420

1521
import matplotlib.pyplot as plt

galleries/users_explain/axes/colorbar_placement.py

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
Colorbars indicate the quantitative extent of image data. Placing in
1111
a figure is non-trivial because room needs to be made for them.
1212
13-
The simplest case is just attaching a colorbar to each axes:
13+
Automatic placement of colorbars
14+
================================
15+
16+
The simplest case is just attaching a colorbar to each axes. Note in this
17+
example that the colorbars steal some space from the parent axes.
1418
"""
1519
import matplotlib.pyplot as plt
1620
import numpy as np
@@ -28,9 +32,9 @@
2832
fig.colorbar(pcm, ax=ax)
2933

3034
# %%
31-
# The first column has the same type of data in both rows, so it may
32-
# be desirable to combine the colorbar which we do by calling
33-
# `.Figure.colorbar` with a list of axes instead of a single axes.
35+
# The first column has the same type of data in both rows, so it may be
36+
# desirable to have just one colorbar. We do this by passing `.Figure.colorbar`
37+
# a list of axes with the *ax* kwarg.
3438

3539
fig, axs = plt.subplots(2, 2)
3640
cmaps = ['RdBu_r', 'viridis']
@@ -41,6 +45,27 @@
4145
cmap=cmaps[col])
4246
fig.colorbar(pcm, ax=axs[:, col], shrink=0.6)
4347

48+
# %%
49+
# The stolen space can lead to axes in the same subplot layout
50+
# being different sizes, which is often undesired if the the
51+
# x-axis on each plot is meant to be comparable as in the following:
52+
53+
fig, axs = plt.subplots(2, 1, figsize=(4, 5), sharex=True)
54+
X = np.random.randn(20, 20)
55+
axs[0].plot(np.sum(X, axis=0))
56+
axs[1].pcolormesh(X)
57+
fig.colorbar(pcm, ax=axs[1], shrink=0.6)
58+
59+
# %%
60+
# This is usually undesired, and can be worked around in various ways, e.g.
61+
# adding a colorbar to the other axes and then removing it. However, the most
62+
# straightforward is to use :ref:`constrained layout <constrainedlayout_guide>`:
63+
64+
fig, axs = plt.subplots(2, 1, figsize=(4, 5), sharex=True, layout='constrained')
65+
axs[0].plot(np.sum(X, axis=0))
66+
axs[1].pcolormesh(X)
67+
fig.colorbar(pcm, ax=axs[1], shrink=0.6)
68+
4469
# %%
4570
# Relatively complicated colorbar layouts are possible using this
4671
# paradigm. Note that this example works far better with
@@ -56,8 +81,67 @@
5681
fig.colorbar(pcm, ax=[axs[2, 1]], location='left')
5782

5883
# %%
59-
# Colorbars with fixed-aspect-ratio axes
60-
# ======================================
84+
# Adjusting the spacing between colorbars and parent axes
85+
# =======================================================
86+
#
87+
# The distance a colorbar is from the parent axes can be adjusted with the
88+
# *pad* keyword argument. This is in units of fraction of the parent axes
89+
# width, and the default for a vertical axes is 0.05 (or 0.15 for a horizontal
90+
# axes).
91+
92+
fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(5, 5))
93+
for ax, pad in zip(axs, [0.025, 0.05, 0.1]):
94+
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
95+
fig.colorbar(pcm, ax=ax, pad=pad, label=f'pad: {pad}')
96+
fig.suptitle("layout='constrained'")
97+
98+
# %%
99+
# Note that if you do not use constrained layout, the pad command makes the
100+
# parent axes shrink:
101+
102+
fig, axs = plt.subplots(3, 1, figsize=(5, 5))
103+
for ax, pad in zip(axs, [0.025, 0.05, 0.1]):
104+
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
105+
fig.colorbar(pcm, ax=ax, pad=pad, label=f'pad: {pad}')
106+
fig.suptitle("No layout manager")
107+
108+
# %%
109+
# Manual placement of colorbars
110+
# =============================
111+
#
112+
# Sometimes the automatic placement provided by ``colorbar`` does not
113+
# give the desired effect. We can manually create an axes and tell
114+
# ``colorbar`` to use that axes by passing the axes to the *cax* keyword
115+
# argument.
116+
#
117+
# Using ``inset_axes``
118+
# --------------------
119+
#
120+
# We can manually create any type of axes for the colorbar to use, but an
121+
# `.Axes.inset_axes` is useful because it is a child of the parent axes and can
122+
# be positioned relative to the parent. Here we add a colorbar centered near
123+
# the bottom of the parent axes.
124+
125+
fig, ax = plt.subplots(layout='constrained', figsize=(4, 4))
126+
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
127+
ax.set_ylim([-4, 20])
128+
cax = ax.inset_axes([0.3, 0.07, 0.4, 0.04])
129+
fig.colorbar(pcm, cax=cax, orientation='horizontal')
130+
131+
# %%
132+
# `.Axes.inset_axes` can also specify its position in data coordinates
133+
# using the *transform* keyword argument if you want your axes at a
134+
# certain data position on the graph:
135+
136+
fig, ax = plt.subplots(layout='constrained', figsize=(4, 4))
137+
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
138+
ax.set_ylim([-4, 20])
139+
cax = ax.inset_axes([7.5, -1.7, 5, 1.2], transform=ax.transData)
140+
fig.colorbar(pcm, cax=cax, orientation='horizontal')
141+
142+
# %%
143+
# Colorbars attached to fixed-aspect-ratio axes
144+
# ---------------------------------------------
61145
#
62146
# Placing colorbars for axes with a fixed aspect ratio pose a particular
63147
# challenge as the parent axes changes size depending on the data view.
@@ -77,9 +161,10 @@
77161
fig.colorbar(pcm, ax=ax, shrink=0.6)
78162

79163
# %%
80-
# One way around this issue is to use an `.Axes.inset_axes` to locate the
81-
# axes in axes coordinates. Note that if you zoom in on the axes, and
82-
# change the shape of the axes, the colorbar will also change position.
164+
# We solve this problem using `.Axes.inset_axes` to locate the axes in "axes
165+
# coordinates" (see :ref:`transforms_tutorial`). Note that if you zoom in on
166+
# the parent axes, and thus change the shape of it, the colorbar will also
167+
# change position.
83168

84169
fig, axs = plt.subplots(2, 2, layout='constrained')
85170
cmaps = ['RdBu_r', 'viridis']
@@ -94,6 +179,12 @@
94179
ax.set_aspect(1/2)
95180
if row == 1:
96181
cax = ax.inset_axes([1.04, 0.2, 0.05, 0.6])
97-
fig.colorbar(pcm, ax=ax, cax=cax)
182+
fig.colorbar(pcm, cax=cax)
98183

99-
plt.show()
184+
# %%
185+
# .. seealso::
186+
#
187+
# :ref:`axes_grid` has methods for manually creating colorbar axes as well:
188+
#
189+
# - :ref:`demo-colorbar-with-inset-locator`
190+
# - :ref:`demo-colorbar-with-axes-divider`

galleries/users_explain/axes/constrainedlayout_guide.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
.. _constrainedlayout_guide:
66
7-
================================
7+
========================
88
Constrained Layout Guide
9-
================================
9+
========================
1010
1111
Use *constrained layout* to fit plots within your figure cleanly.
1212

0 commit comments

Comments
 (0)