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

Skip to content

Commit 9f6e0e6

Browse files
committed
FIX: rename subfigure
1 parent 318d878 commit 9f6e0e6

File tree

7 files changed

+63
-63
lines changed

7 files changed

+63
-63
lines changed

examples/subplots_axes_and_figures/gridspec_nested.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set the position for a nested grid of subplots.
88
99
Note that the same functionality can be achieved more directly with
10-
`~.figure.PanelBase.subpanels`:
10+
`~.figure.FigureBase.subfigures`:
1111
:doc:`nested gridspecs</gallery/subplots_axes_and_figures/subpanels>`,
1212
1313
"""

examples/subplots_axes_and_figures/subpanels.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""
2-
================
3-
Figure subpanels
4-
================
2+
=================
3+
Figure subfigures
4+
=================
55
66
Sometimes it is desirable to have a figure with two different layouts in it.
77
This can be achieved with
88
:doc:`nested gridspecs</gallery/subplots_axes_and_figures/gridspec_nested>`,
99
but having a virtual figure with its own artists is helpful, so
10-
Matplotlib also has "subpanels", accessed by calling
11-
`matplotlib.figure.Figure.add_subpanel` in a way that is analagous to
12-
`matplotlib.figure.Figure.add_subplot`, or `matplotlib.figure.Figure.subpanels`
13-
to make an array of subpanels. Note that subpanels can also have their own
14-
child subpanels.
10+
Matplotlib also has "subfigures", accessed by calling
11+
`matplotlib.figure.Figure.add_subfigure` in a way that is analagous to
12+
`matplotlib.figure.Figure.add_subplot`, or
13+
`matplotlib.figure.Figure.subfigures` to make an array of subfigures. Note
14+
that subfigures can also have their own child subfigures.
1515
1616
.. note::
17-
``subpanel`` is new in v3.4, and the API is still provisional.
17+
``subfigure`` is new in v3.4, and the API is still provisional.
1818
1919
"""
2020
import matplotlib.pyplot as plt
@@ -32,25 +32,25 @@ def example_plot(ax, fontsize=12, hide_labels=False):
3232

3333
# gridspec inside gridspec
3434
fig = plt.figure(constrained_layout=True, figsize=(10, 4))
35-
subpanels = fig.subpanels(1, 2, wspace=0.07)
35+
subfigs = fig.subfigures(1, 2, wspace=0.07)
3636

37-
axsLeft = subpanels[0].subplots(1, 2, sharey=True)
38-
subpanels[0].set_facecolor('0.75')
37+
axsLeft = subfigs[0].subplots(1, 2, sharey=True)
38+
subfigs[0].set_facecolor('0.75')
3939
for ax in axsLeft:
4040
pc = example_plot(ax)
41-
subpanels[0].suptitle('Left plots', fontsize='x-large')
42-
subpanels[0].colorbar(pc, shrink=0.6, ax=axsLeft, location='bottom')
41+
subfigs[0].suptitle('Left plots', fontsize='x-large')
42+
subfigs[0].colorbar(pc, shrink=0.6, ax=axsLeft, location='bottom')
4343

44-
axsRight = subpanels[1].subplots(3, 1, sharex=True)
44+
axsRight = subfigs[1].subplots(3, 1, sharex=True)
4545
for nn, ax in enumerate(axsRight):
4646
pc = example_plot(ax, hide_labels=True)
4747
if nn == 2:
4848
ax.set_xlabel('xlabel')
4949
if nn == 1:
5050
ax.set_ylabel('ylabel')
51-
subpanels[1].set_facecolor('0.85')
52-
subpanels[1].colorbar(pc, shrink=0.6, ax=axsRight)
53-
subpanels[1].suptitle('Right plots', fontsize='x-large')
51+
subfigs[1].set_facecolor('0.85')
52+
subfigs[1].colorbar(pc, shrink=0.6, ax=axsRight)
53+
subfigs[1].suptitle('Right plots', fontsize='x-large')
5454

5555
fig.suptitle('Figure suptitle', fontsize='xx-large')
5656

lib/matplotlib/figure.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
44
`Figure`
55
Top level `~matplotlib.artist.Artist`, which holds all plot elements.
6-
Many methods are implimented in `PanelBase`.
6+
Many methods are implimented in `FigureBase`.
77
8-
`SubPanel`
8+
`SubFigure`
99
A logical figure inside a figure, usually added to a figure (or parent
10-
`SubPanel`) with `Figure.add_subpanel` or `Figure.subpanels` methods
10+
`SubFigure`) with `Figure.add_subfigure` or `Figure.subfigures` methods
1111
(provisional API v3.4).
1212
1313
`SubplotParams`
@@ -219,9 +219,9 @@ def update(self, left=None, bottom=None, right=None, top=None,
219219
self.hspace = hspace
220220

221221

222-
class PanelBase(Artist):
222+
class FigureBase(Artist):
223223
"""
224-
Base class for `.figure.Figure` and `.figure.SubPanel` containing the
224+
Base class for `.figure.Figure` and `.figure.SubFigure` containing the
225225
methods that add artists to the figure or panel, create axes, etc.
226226
"""
227227
def __init__(self):
@@ -1408,26 +1408,26 @@ def add_gridspec(self, nrows=1, ncols=1, **kwargs):
14081408
self._gridspecs.append(gs)
14091409
return gs
14101410

1411-
def subpanels(self, nrows=1, ncols=1, squeeze=True,
1411+
def subfigures(self, nrows=1, ncols=1, squeeze=True,
14121412
wspace=None, hspace=None,
14131413
width_ratios=None, height_ratios=None,
14141414
**kwargs):
14151415
"""
1416-
Add a subpanel to this figure or subpanel. A subpanel has the same
1416+
Add a subfigure to this figure or subfigure. A subfigure has the same
14171417
artist methods as a figure, and is logically the same as a figure.
14181418
14191419
Parameters
14201420
----------
14211421
nrows, ncols : int, default: 1
1422-
Number of rows/columns of the subpanel grid.
1422+
Number of rows/columns of the subfigure grid.
14231423
14241424
squeeze : boolean, default: True
14251425
If True, extra dimensions are squeezed out from the returned
1426-
array of subpanels.
1426+
array of subfigures.
14271427
14281428
wspace, hspace : float, default: None
1429-
The amount of width/height reserved for space between subpanels,
1430-
expressed as a fraction of the average subpanel width.
1429+
The amount of width/height reserved for space between subfigures,
1430+
expressed as a fraction of the average subfigure width.
14311431
If not given, the values will be inferred from a figure or
14321432
rcParams when necessary.
14331433
@@ -1449,20 +1449,20 @@ def subpanels(self, nrows=1, ncols=1, squeeze=True,
14491449
sfarr = np.empty((nrows, ncols), dtype=object)
14501450
for i in range(ncols):
14511451
for j in range(nrows):
1452-
sfarr[j, i] = self.add_subpanel(gs[j, i], **kwargs)
1452+
sfarr[j, i] = self.add_subfigure(gs[j, i], **kwargs)
14531453

14541454
if squeeze:
14551455
# Discarding unneeded dimensions that equal 1. If we only have one
1456-
# subpanel, just return it instead of a 1-element array.
1456+
# subfigure, just return it instead of a 1-element array.
14571457
return sfarr.item() if sfarr.size == 1 else sfarr.squeeze()
14581458
else:
14591459
# Returned axis array will be always 2-d, even if nrows=ncols=1.
14601460
return sfarr
14611461

14621462
return sfarr
14631463

1464-
def add_subpanel(self, subplotspec, **kwargs):
1465-
sf = SubPanel(subplotspec, self, **kwargs)
1464+
def add_subfigure(self, subplotspec, **kwargs):
1465+
sf = SubFigure(subplotspec, self, **kwargs)
14661466
self.panels += [sf]
14671467
return sf
14681468

@@ -1887,21 +1887,21 @@ def _set_artist_props(self, a):
18871887
a.set_transform(self.transPanel)
18881888

18891889

1890-
class SubPanel(PanelBase):
1890+
class SubFigure(FigureBase):
18911891
"""
1892-
Logical panel that can be placed in a figure typically using
1893-
`.Figure.add_subpanel` or `.SubPanel.add_subpanel`, or
1894-
`.SubPanel.subpanels`. A panel has the same methods as a figure
1892+
Logical figure that can be placed inside a figure typically using
1893+
`.Figure.add_subfigure` or `.SubFigure.add_subfigure`, or
1894+
`.SubFigure.subfigures`. A panel has the same methods as a figure
18951895
except for those particularly tied to the size or dpi of the figure, and
18961896
is confined to a prescribed region of the figure. For example the
1897-
following puts two subpanels side-by-side::
1897+
following puts two subfigures side-by-side::
18981898
18991899
fig = plt.figure()
1900-
spanels = fig.subpanels(1, 2)
1901-
axsL = spanels[0].subplots(1, 2)
1902-
axsR = spanels[0].subplots(2, 1)
1900+
sfigs = fig.subfigures(1, 2)
1901+
axsL = sfigs[0].subplots(1, 2)
1902+
axsR = sfigs[0].subplots(2, 1)
19031903
1904-
See :doc:`/gallery/subplots_axes_and_figures/subpanels`
1904+
See :doc:`/gallery/subplots_axes_and_figures/subfigures`
19051905
"""
19061906

19071907
def __init__(self, subplotspec, parent, *,
@@ -1913,11 +1913,11 @@ def __init__(self, subplotspec, parent, *,
19131913
Parameters
19141914
----------
19151915
subplotspec : `.gridspec.SubplotSpec`
1916-
defines the region in a parent gridspec where the subpanel will
1916+
defines the region in a parent gridspec where the subfigure will
19171917
be placed
19181918
1919-
parent : `.figure.Figure` or `.figure.SubPanel`
1920-
Figure or subpanel that contains the SubPanel. SubPanels
1919+
parent : `.figure.Figure` or `.figure.SubFigure`
1920+
Figure or subfigure that contains the SubFigure. SubFigures
19211921
can be nested.
19221922
19231923
facecolor : default: :rc:`figure.facecolor`
@@ -1945,7 +1945,7 @@ def __init__(self, subplotspec, parent, *,
19451945
self._subplotspec = subplotspec
19461946
self._parent = parent
19471947
self.figure = parent.figure
1948-
# subpanels use the parent axstack
1948+
# subfigures use the parent axstack
19491949
self._axstack = parent._axstack
19501950
self.subplotpars = parent.subplotpars
19511951
self.dpi_scale_trans = parent.dpi_scale_trans
@@ -2040,7 +2040,7 @@ def init_layoutgrid(self):
20402040

20412041
def get_axes(self):
20422042
"""
2043-
Return a list of axes in the SubPanel. You can access and modify the
2043+
Return a list of axes in the SubFigure. You can access and modify the
20442044
axes in the Figure through this list.
20452045
"""
20462046
return self._localaxes.as_list()
@@ -2049,8 +2049,8 @@ def get_axes(self):
20492049
List of axes in the Figure. You can access and modify the axes
20502050
in the Figure through this list.
20512051
2052-
Do not modify the list itself. Instead, use "`~.SubPanel.add_axes`,
2053-
`~.SubPanel.add_subplot` or `~.SubPanel.delaxes` to add or remove an
2052+
Do not modify the list itself. Instead, use "`~.SubFigure.add_axes`,
2053+
`~.SubFigure.add_subplot` or `~.SubFigure.delaxes` to add or remove an
20542054
axes.
20552055
""")
20562056

@@ -2074,7 +2074,7 @@ def draw(self, renderer):
20742074
self.stale = False
20752075

20762076

2077-
class Figure(PanelBase):
2077+
class Figure(FigureBase):
20782078
"""
20792079
The top level container for all the plot elements.
20802080
@@ -2215,7 +2215,7 @@ def __init__(self,
22152215
self._cachedRenderer = None
22162216

22172217
self.set_constrained_layout(constrained_layout)
2218-
# stub for subpanels:
2218+
# stub for subfigures:
22192219
self.panels = []
22202220

22212221
# groupers to keep track of x and y labels we want to align.

lib/matplotlib/tests/test_figure.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,13 @@ def test_reused_gridspec():
799799
assert gs1 == gs3
800800

801801

802-
@image_comparison(['test_subpanel.png'], style='mpl20',
802+
@image_comparison(['test_subfigure.png'], style='mpl20',
803803
savefig_kwarg={'facecolor': 'teal'},
804804
remove_text=False)
805-
def test_subpanel():
805+
def test_subfigure():
806806
np.random.seed(19680808)
807807
fig = plt.figure(constrained_layout=True)
808-
sub = fig.subpanels(1, 2)
808+
sub = fig.subfigures(1, 2)
809809

810810
axs = sub[0].subplots(2, 2)
811811
for ax in axs.flat:
@@ -822,15 +822,15 @@ def test_subpanel():
822822
fig.suptitle('Figure suptitle', fontsize='xx-large')
823823

824824

825-
@image_comparison(['test_subpanel_ss.png'], style='mpl20',
825+
@image_comparison(['test_subfigure_ss.png'], style='mpl20',
826826
savefig_kwarg={'facecolor': 'teal'},
827827
remove_text=False)
828-
def test_subpanel_ss():
828+
def test_subfigure_ss():
829829
np.random.seed(19680808)
830830
fig = plt.figure(constrained_layout=True)
831831
gs = fig.add_gridspec(1, 2)
832832

833-
sub = fig.add_subpanel(gs[0], facecolor='pink')
833+
sub = fig.add_subfigure(gs[0], facecolor='pink')
834834

835835
axs = sub.subplots(2, 2)
836836
for ax in axs.flat:

tutorials/advanced/transforms_tutorial.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
| | |is bottom left of the axes, and |
3030
| | |(1, 1) is top right of the axes. |
3131
+----------------+-----------------------------+-----------------------------------+
32-
|"subpanel" |``subpanel.transPanel`` |The coordinate system of the |
33-
| | |`.SubPanel`; (0, 0) is bottom left |
34-
| | |of the subpanel, and (1, 1) is top |
35-
| | |right of the subpanel. If a |
36-
| | |figure has no subpanels, this is |
32+
|"subfigure" |``subfigure.transPanel`` |The coordinate system of the |
33+
| | |`.SubFigure`; (0, 0) is bottom left|
34+
| | |of the subfigure, and (1, 1) is top|
35+
| | |right of the subfigure. If a |
36+
| | |figure has no subfigures, this is |
3737
| | |the same as ``transFigure``. |
3838
+----------------+-----------------------------+-----------------------------------+
3939
|"figure" |``fig.transFigure`` |The coordinate system of the |

0 commit comments

Comments
 (0)