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

Skip to content

Commit a319146

Browse files
authored
Merge branch 'matplotlib:main' into jaco-doc-update
2 parents f4dcad7 + 113fc77 commit a319146

Some content is hidden

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

56 files changed

+695
-462
lines changed

doc/api/axes_api.rst

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ The Axes class
2727
:no-undoc-members:
2828
:show-inheritance:
2929

30-
31-
Subplots
32-
========
33-
34-
.. autosummary::
35-
:toctree: _as_gen
36-
:template: autosummary.rst
37-
:nosignatures:
38-
39-
SubplotBase
40-
subplot_class_factory
41-
4230
Plotting
4331
========
4432

@@ -313,6 +301,7 @@ Axis labels, title, and legend
313301
Axes.get_xlabel
314302
Axes.set_ylabel
315303
Axes.get_ylabel
304+
Axes.label_outer
316305

317306
Axes.set_title
318307
Axes.get_title
@@ -484,6 +473,9 @@ Axes position
484473
Axes.get_axes_locator
485474
Axes.set_axes_locator
486475

476+
Axes.get_subplotspec
477+
Axes.set_subplotspec
478+
487479
Axes.reset_position
488480

489481
Axes.get_position
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
All Axes have ``get_subplotspec`` and ``get_gridspec`` methods now, which returns None for Axes not positioned via a gridspec
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Previously, this method was only present for Axes positioned via a gridspec.
4+
Following this change, checking ``hasattr(ax, "get_gridspec")`` should now be
5+
replaced by ``ax.get_gridspec() is not None``. For compatibility with older
6+
Matplotlib releases, one can also check
7+
``hasattr(ax, "get_gridspec") and ax.get_gridspec() is not None``.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``num2julian``, ``julian2num`` and ``JULIAN_OFFSET``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... of the `.dates` module are deprecated without replacements. These are
5+
undocumented and not exported. If you rely on these, please make a local copy.

doc/api/prev_api_changes/api_changes_3.3.0/deprecations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ are deprecated. Panning and zooming are now implemented using the
328328

329329
Passing None to various Axes subclass factories
330330
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
331-
Support for passing ``None`` as base class to `.axes.subplot_class_factory`,
331+
Support for passing ``None`` as base class to ``axes.subplot_class_factory``,
332332
``axes_grid1.parasite_axes.host_axes_class_factory``,
333333
``axes_grid1.parasite_axes.host_subplot_class_factory``,
334334
``axes_grid1.parasite_axes.parasite_axes_class_factory``, and

doc/api/prev_api_changes/api_changes_3.4.0/deprecations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Subplot-related attributes and methods
3838
Some ``SubplotBase`` methods and attributes have been deprecated and/or moved
3939
to `.SubplotSpec`:
4040

41-
- ``get_geometry`` (use `.SubplotBase.get_subplotspec` instead),
42-
- ``change_geometry`` (use `.SubplotBase.set_subplotspec` instead),
41+
- ``get_geometry`` (use ``SubplotBase.get_subplotspec`` instead),
42+
- ``change_geometry`` (use ``SubplotBase.set_subplotspec`` instead),
4343
- ``is_first_row``, ``is_last_row``, ``is_first_col``, ``is_last_col`` (use the
4444
corresponding methods on the `.SubplotSpec` instance instead),
4545
- ``update_params`` (now a no-op),

doc/devel/color_changes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Default color changes
55
*********************
66

7-
As discussed at length elsewhere [insert links], ``jet`` is an
7+
As discussed at length `elsewhere <https://bids.github.io/colormap/>`__ ,
8+
``jet`` is an
89
empirically bad colormap and should not be the default colormap.
910
Due to the position that changing the appearance of the plot breaks
1011
backward compatibility, this change has been put off for far longer

doc/devel/contributing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ API consistency and stability are of great value. Therefore, API changes
331331
(e.g. signature changes, behavior changes, removals) will only be conducted
332332
if the added benefit is worth the user effort for adapting.
333333

334+
Because we are a visualization library our primary output is the final
335+
visualization the user sees. Thus it is our :ref:`long standing
336+
<color_changes>` policy that the appearance of the figure is part of the API
337+
and any changes, either semantic or esthetic, will be treated as a
338+
backwards-incompatible API change.
339+
334340
API changes in Matplotlib have to be performed following the deprecation process
335341
below, except in very rare circumstances as deemed necessary by the development team.
336342
This ensures that users are notified before the change will take effect and thus

doc/users/prev_whats_new/whats_new_3.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ independent on the axes size or units. To revert to the previous behaviour
141141
set the axes' aspect ratio to automatic by using ``ax.set_aspect("auto")`` or
142142
``plt.axis("auto")``.
143143

144-
Add ``ax.get_gridspec`` to `.SubplotBase`
145-
-----------------------------------------
144+
Add ``ax.get_gridspec`` to ``SubplotBase``
145+
------------------------------------------
146146

147-
New method `.SubplotBase.get_gridspec` is added so that users can
147+
New method ``SubplotBase.get_gridspec`` is added so that users can
148148
easily get the gridspec that went into making an axes:
149149

150150
.. code::

examples/animation/simple_scatter.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
=============================
3+
Animated scatter saved as GIF
4+
=============================
5+
6+
"""
7+
import numpy as np
8+
import matplotlib.pyplot as plt
9+
import matplotlib.animation as animation
10+
11+
fig, ax = plt.subplots()
12+
ax.set_xlim([0, 10])
13+
14+
scat = ax.scatter(1, 0)
15+
x = np.linspace(0, 10)
16+
17+
18+
def animate(i):
19+
scat.set_offsets((x[i], 0))
20+
return scat,
21+
22+
ani = animation.FuncAnimation(fig, animate, repeat=True,
23+
frames=len(x) - 1, interval=50)
24+
25+
# To save the animation using Pillow as a gif
26+
# writer = animation.PillowWriter(fps=15,
27+
# metadata=dict(artist='Me'),
28+
# bitrate=1800)
29+
# ani.save('scatter.gif', writer=writer)
30+
31+
plt.show()

lib/matplotlib/_constrained_layout.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
187187

188188
# for each axes at the local level add its gridspec:
189189
for ax in fig._localaxes:
190-
if hasattr(ax, 'get_subplotspec'):
191-
gs = ax.get_subplotspec().get_gridspec()
190+
gs = ax.get_gridspec()
191+
if gs is not None:
192192
layoutgrids = make_layoutgrids_gs(layoutgrids, gs)
193193

194194
return layoutgrids
@@ -248,24 +248,22 @@ def check_no_collapsed_axes(layoutgrids, fig):
248248
ok = check_no_collapsed_axes(layoutgrids, sfig)
249249
if not ok:
250250
return False
251-
252251
for ax in fig.axes:
253-
if hasattr(ax, 'get_subplotspec'):
254-
gs = ax.get_subplotspec().get_gridspec()
255-
if gs in layoutgrids:
256-
lg = layoutgrids[gs]
257-
for i in range(gs.nrows):
258-
for j in range(gs.ncols):
259-
bb = lg.get_inner_bbox(i, j)
260-
if bb.width <= 0 or bb.height <= 0:
261-
return False
252+
gs = ax.get_gridspec()
253+
if gs in layoutgrids: # also implies gs is not None.
254+
lg = layoutgrids[gs]
255+
for i in range(gs.nrows):
256+
for j in range(gs.ncols):
257+
bb = lg.get_inner_bbox(i, j)
258+
if bb.width <= 0 or bb.height <= 0:
259+
return False
262260
return True
263261

264262

265263
def compress_fixed_aspect(layoutgrids, fig):
266264
gs = None
267265
for ax in fig.axes:
268-
if not hasattr(ax, 'get_subplotspec'):
266+
if ax.get_subplotspec() is None:
269267
continue
270268
ax.apply_aspect()
271269
sub = ax.get_subplotspec()
@@ -357,7 +355,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
357355
layoutgrids[sfig].parent.edit_outer_margin_mins(margins, ss)
358356

359357
for ax in fig._localaxes:
360-
if not hasattr(ax, 'get_subplotspec') or not ax.get_in_layout():
358+
if not ax.get_subplotspec() or not ax.get_in_layout():
361359
continue
362360

363361
ss = ax.get_subplotspec()
@@ -488,8 +486,8 @@ def match_submerged_margins(layoutgrids, fig):
488486
for sfig in fig.subfigs:
489487
match_submerged_margins(layoutgrids, sfig)
490488

491-
axs = [a for a in fig.get_axes() if (hasattr(a, 'get_subplotspec')
492-
and a.get_in_layout())]
489+
axs = [a for a in fig.get_axes()
490+
if a.get_subplotspec() is not None and a.get_in_layout()]
493491

494492
for ax1 in axs:
495493
ss1 = ax1.get_subplotspec()
@@ -620,7 +618,7 @@ def reposition_axes(layoutgrids, fig, renderer, *,
620618
wspace=wspace, hspace=hspace)
621619

622620
for ax in fig._localaxes:
623-
if not hasattr(ax, 'get_subplotspec') or not ax.get_in_layout():
621+
if ax.get_subplotspec() is None or not ax.get_in_layout():
624622
continue
625623

626624
# grid bbox is in Figure coordinates, but we specify in panel
@@ -742,10 +740,9 @@ def reset_margins(layoutgrids, fig):
742740
for sfig in fig.subfigs:
743741
reset_margins(layoutgrids, sfig)
744742
for ax in fig.axes:
745-
if hasattr(ax, 'get_subplotspec') and ax.get_in_layout():
746-
ss = ax.get_subplotspec()
747-
gs = ss.get_gridspec()
748-
if gs in layoutgrids:
743+
if ax.get_in_layout():
744+
gs = ax.get_gridspec()
745+
if gs in layoutgrids: # also implies gs is not None.
749746
layoutgrids[gs].reset_margins()
750747
layoutgrids[fig].reset_margins()
751748

lib/matplotlib/axes/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
from ._subplots import *
1+
from . import _base
22
from ._axes import *
3+
4+
# Backcompat.
5+
from ._axes import Axes as Subplot
6+
7+
8+
class _SubplotBaseMeta(type):
9+
def __instancecheck__(self, obj):
10+
return (isinstance(obj, _base._AxesBase)
11+
and obj.get_subplotspec() is not None)
12+
13+
14+
class SubplotBase(metaclass=_SubplotBaseMeta):
15+
pass
16+
17+
18+
def subplot_class_factory(cls): return cls

0 commit comments

Comments
 (0)