Skip to content

Commit

Permalink
Merge branch 'main' into stubtest_script
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden authored Sep 28, 2023
2 parents 61661f1 + e3a5cee commit d7ad3ad
Show file tree
Hide file tree
Showing 45 changed files with 510 additions and 420 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ repos:
- id: rstcheck
additional_dependencies:
- sphinx>=1.8.1
- tomli
19 changes: 0 additions & 19 deletions ci/mypy-stubtest-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ matplotlib.ticker.LogitLocator.nonsingular
matplotlib.backend_bases._Mode.__new__
matplotlib.units.Number.__hash__

# Property read-write vs read-only weirdness, fix if possible
matplotlib.offsetbox.DraggableBase.canvas
matplotlib.offsetbox.DraggableBase.cids
matplotlib.transforms.BboxTransform.is_separable
matplotlib.transforms.BboxTransformFrom.is_separable
matplotlib.transforms.BboxTransformTo.is_separable
matplotlib.transforms.BlendedAffine2D.is_separable
matplotlib.transforms.CompositeGenericTransform.is_separable
matplotlib.transforms.TransformWrapper.input_dims
matplotlib.transforms.TransformWrapper.is_separable
matplotlib.transforms.TransformWrapper.output_dims

# 3.6 Pending deprecations
matplotlib.figure.Figure.set_constrained_layout
matplotlib.figure.Figure.set_constrained_layout_pads
Expand All @@ -52,7 +40,6 @@ matplotlib.figure.Figure.set_tight_layout
# 3.7 deprecations
matplotlib.cm.register_cmap
matplotlib.cm.unregister_cmap
matplotlib.collections.PolyCollection.span_where

# 3.8 deprecations
matplotlib.contour.ContourSet.allkinds
Expand All @@ -63,16 +50,10 @@ matplotlib.contour.ContourSet.tlinewidths
# positional-only argument name lacking leading underscores
matplotlib.axes._base._AxesBase.axis

# Other dynamic python behaviors not type hinted
matplotlib.rcsetup.defaultParams

# Maybe should be abstractmethods, required for subclasses, stubs define once
matplotlib.tri.*TriInterpolator.__call__
matplotlib.tri.*TriInterpolator.gradient

# Functionally a method call, but actually a class instance, type hinted as former
matplotlib.rcsetup.validate_fillstyle

# TypeVar used only in type hints
matplotlib.backend_bases.FigureCanvasBase._T
matplotlib.backend_managers.ToolManager._T
Expand Down
2 changes: 1 addition & 1 deletion doc/api/artist_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Inheritance Diagrams
====================

.. 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
.. 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
:parts: 1
:private-bases:

Expand Down
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behavior/26788-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
``axvspan`` and ``axhspan`` now return ``Rectangle``\s, not ``Polygons``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This change allows using `~.Axes.axhspan` to draw an annulus on polar axes.

This change also affects other elements built via `~.Axes.axvspan` and
`~.Axes.axhspan`, such as ``Slider.poly``.
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/26902-RP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``Line2D``
~~~~~~~~~~

When creating a Line2D or using `.Line2D.set_xdata` and `.Line2D.set_ydata`,
passing x/y data as non sequence is now an error.
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/removals/26852-OG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@

... of the `.dates` module are removed without replacements. These were
undocumented and not exported.

Julian dates in Matplotlib were calculated from a Julian date epoch: ``jdate =
(date - np.datetime64(EPOCH)) / np.timedelta64(1, 'D')``. Conversely, a Julian
date was converted to datetime as ``date = np.timedelta64(int(jdate * 24 *
3600), 's') + np.datetime64(EPOCH)``. Matplotlib was using
``EPOCH='-4713-11-24T12:00'`` so that 2000-01-01 at 12:00 is 2_451_545.0 (see
<https://en.wikipedia.org/wiki/Julian_day>`).
11 changes: 5 additions & 6 deletions doc/api/next_api_changes/removals/26872-AD.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
``repeat``
~~~~~~~~~~
... of `.TimedAnimation` is removed without replacements.
``save_count``
~~~~~~~~~~~~~~
... of `.FuncAnimation` is removed without replacements.
``Animation`` attributes
~~~~~~~~~~~~~~~~~~~~~~~~

The attributes ``repeat`` of `.TimedAnimation` and subclasses and
``save_count`` of `.FuncAnimation` are considered private and removed.
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/removals/26874-AG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``collections.PolyCollection.span_where`` and ``collections.BrokenBarHCollection``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... removed as it was deprecated during 3.7. Use ``fill_between`` instead
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/removals/26918-EW.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``Quiver.quiver_doc`` and ``Barbs.barbs_doc``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... are removed. These are the doc-string and should not be accessible as a named class member.
5 changes: 5 additions & 0 deletions doc/users/next_whats_new/polar-line-spans.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``axhline`` and ``axhspan`` on polar axes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... now draw circles and circular arcs (`~.Axes.axhline`) or annuli and wedges
(`~.Axes.axhspan`).
3 changes: 3 additions & 0 deletions doc/users/next_whats_new/stdfmt-axisartist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``axisartist`` can now be used together with standard ``Formatters``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... instead of being limited to axisartist-specific ones.
2 changes: 1 addition & 1 deletion doc/users/prev_whats_new/whats_new_1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Added size related functions to specialized `.Collection`\s
Added the ``get_size`` and ``set_size`` functions to control the size of
elements of specialized collections (
:class:`~matplotlib.collections.AsteriskPolygonCollection`
:class:`~matplotlib.collections.BrokenBarHCollection`
``matplotlib.collections.BrokenBarHCollection``
:class:`~matplotlib.collections.CircleCollection`
:class:`~matplotlib.collections.PathCollection`
:class:`~matplotlib.collections.PolyCollection`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
.. _demo-colorbar-with-axes-divider:
=========================
Colorbar with AxesDivider
=========================
Expand All @@ -8,6 +10,10 @@
method of the `.AxesDivider` can then be used to create a new axes on a given
side ("top", "right", "bottom", or "left") of the original axes. This example
uses `.append_axes` to add colorbars next to axes.
Users should consider simply passing the main axes to the *ax* keyword argument of
`~.Figure.colorbar` instead of creating a locatable axes manually like this.
See :ref:`colorbar_placement`.
"""

import matplotlib.pyplot as plt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"""
.. _demo-colorbar-with-inset-locator:
==============================================================
Controlling the position and size of colorbars with Inset Axes
==============================================================
This example shows how to control the position, height, and width of
colorbars using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
This example shows how to control the position, height, and width of colorbars
using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
Inset axes placement is controlled as for legends: either by providing a *loc*
option ("upper right", "best", ...), or by providing a locator with respect to
the parent bbox. Parameters such as *bbox_to_anchor* and *borderpad* likewise
work in the same way, and are also demonstrated here.
Users should consider using `.Axes.inset_axes` instead (see
:ref:`colorbar_placement`).
"""

import matplotlib.pyplot as plt
Expand Down
113 changes: 102 additions & 11 deletions galleries/users_explain/axes/colorbar_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
Colorbars indicate the quantitative extent of image data. Placing in
a figure is non-trivial because room needs to be made for them.
The simplest case is just attaching a colorbar to each axes:
Automatic placement of colorbars
================================
The simplest case is just attaching a colorbar to each axes. Note in this
example that the colorbars steal some space from the parent axes.
"""
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -28,9 +32,9 @@
fig.colorbar(pcm, ax=ax)

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

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

# %%
# The stolen space can lead to axes in the same subplot layout
# being different sizes, which is often undesired if the the
# x-axis on each plot is meant to be comparable as in the following:

fig, axs = plt.subplots(2, 1, figsize=(4, 5), sharex=True)
X = np.random.randn(20, 20)
axs[0].plot(np.sum(X, axis=0))
axs[1].pcolormesh(X)
fig.colorbar(pcm, ax=axs[1], shrink=0.6)

# %%
# This is usually undesired, and can be worked around in various ways, e.g.
# adding a colorbar to the other axes and then removing it. However, the most
# straightforward is to use :ref:`constrained layout <constrainedlayout_guide>`:

fig, axs = plt.subplots(2, 1, figsize=(4, 5), sharex=True, layout='constrained')
axs[0].plot(np.sum(X, axis=0))
axs[1].pcolormesh(X)
fig.colorbar(pcm, ax=axs[1], shrink=0.6)

# %%
# Relatively complicated colorbar layouts are possible using this
# paradigm. Note that this example works far better with
Expand All @@ -56,8 +81,67 @@
fig.colorbar(pcm, ax=[axs[2, 1]], location='left')

# %%
# Colorbars with fixed-aspect-ratio axes
# ======================================
# Adjusting the spacing between colorbars and parent axes
# =======================================================
#
# The distance a colorbar is from the parent axes can be adjusted with the
# *pad* keyword argument. This is in units of fraction of the parent axes
# width, and the default for a vertical axes is 0.05 (or 0.15 for a horizontal
# axes).

fig, axs = plt.subplots(3, 1, layout='constrained', figsize=(5, 5))
for ax, pad in zip(axs, [0.025, 0.05, 0.1]):
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
fig.colorbar(pcm, ax=ax, pad=pad, label=f'pad: {pad}')
fig.suptitle("layout='constrained'")

# %%
# Note that if you do not use constrained layout, the pad command makes the
# parent axes shrink:

fig, axs = plt.subplots(3, 1, figsize=(5, 5))
for ax, pad in zip(axs, [0.025, 0.05, 0.1]):
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
fig.colorbar(pcm, ax=ax, pad=pad, label=f'pad: {pad}')
fig.suptitle("No layout manager")

# %%
# Manual placement of colorbars
# =============================
#
# Sometimes the automatic placement provided by ``colorbar`` does not
# give the desired effect. We can manually create an axes and tell
# ``colorbar`` to use that axes by passing the axes to the *cax* keyword
# argument.
#
# Using ``inset_axes``
# --------------------
#
# We can manually create any type of axes for the colorbar to use, but an
# `.Axes.inset_axes` is useful because it is a child of the parent axes and can
# be positioned relative to the parent. Here we add a colorbar centered near
# the bottom of the parent axes.

fig, ax = plt.subplots(layout='constrained', figsize=(4, 4))
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
ax.set_ylim([-4, 20])
cax = ax.inset_axes([0.3, 0.07, 0.4, 0.04])
fig.colorbar(pcm, cax=cax, orientation='horizontal')

# %%
# `.Axes.inset_axes` can also specify its position in data coordinates
# using the *transform* keyword argument if you want your axes at a
# certain data position on the graph:

fig, ax = plt.subplots(layout='constrained', figsize=(4, 4))
pcm = ax.pcolormesh(np.random.randn(20, 20), cmap='viridis')
ax.set_ylim([-4, 20])
cax = ax.inset_axes([7.5, -1.7, 5, 1.2], transform=ax.transData)
fig.colorbar(pcm, cax=cax, orientation='horizontal')

# %%
# Colorbars attached to fixed-aspect-ratio axes
# ---------------------------------------------
#
# Placing colorbars for axes with a fixed aspect ratio pose a particular
# challenge as the parent axes changes size depending on the data view.
Expand All @@ -77,9 +161,10 @@
fig.colorbar(pcm, ax=ax, shrink=0.6)

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

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

plt.show()
# %%
# .. seealso::
#
# :ref:`axes_grid` has methods for manually creating colorbar axes as well:
#
# - :ref:`demo-colorbar-with-inset-locator`
# - :ref:`demo-colorbar-with-axes-divider`
4 changes: 2 additions & 2 deletions galleries/users_explain/axes/constrainedlayout_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
.. _constrainedlayout_guide:
================================
========================
Constrained Layout Guide
================================
========================
Use *constrained layout* to fit plots within your figure cleanly.
Expand Down
Loading

0 comments on commit d7ad3ad

Please sign in to comment.