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

Skip to content

Commit de92651

Browse files
committed
DOC: add example, build toc for Figure
1 parent 8b23111 commit de92651

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

doc/api/figure_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ Classes
1515
:toctree: _as_gen/
1616
:template: autosummary.rst
1717
:nosignatures:
18+
:inhereted-members:
1819

1920
AxesStack
21+
SubPanel
2022
Figure
2123
SubplotParams
2224

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
================
3+
Nested Subpanels
4+
================
5+
Sometimes it is desirable to have a figure that has two different
6+
layouts in it. This can be achieved with
7+
:doc:`nested gridspecs</gallery/subplots_axes_and_figures/gridspec_nested>`
8+
but having a virtual figure with its own artists is helpful, so
9+
Matplotlib also has "subpanels", usually implimented by calling
10+
``.figure.PanelBase.add_subpanel`` in a way that is analagous to
11+
``.figure.PanelBase.add_subplot``.
12+
"""
13+
import matplotlib.pyplot as plt
14+
import numpy as np
15+
16+
17+
def example_plot(ax, fontsize=12, hide_labels=False):
18+
pc = ax.pcolormesh(np.random.randn(30, 30))
19+
if not hide_labels:
20+
ax.set_xlabel('x-label', fontsize=fontsize)
21+
ax.set_ylabel('y-label', fontsize=fontsize)
22+
ax.set_title('Title', fontsize=fontsize)
23+
return pc
24+
25+
26+
# gridspec inside gridspec
27+
fig = plt.figure(constrained_layout=True, figsize=(10, 4))
28+
subpanels = fig.subpanels(1, 2, wspace=0.07)
29+
30+
axsLeft = subpanels[0].subplots(1, 2, sharey=True)
31+
subpanels[0].set_facecolor('0.75')
32+
for ax in axsLeft:
33+
pc = example_plot(ax)
34+
subpanels[0].suptitle('Left plots', fontsize='x-large')
35+
subpanels[0].colorbar(pc, shrink=0.6, ax=axsLeft, location='bottom')
36+
37+
axsRight = subpanels[1].subplots(3, 1, sharex=True)
38+
for nn, ax in enumerate(axsRight):
39+
pc = example_plot(ax, hide_labels=True)
40+
if nn == 2:
41+
ax.set_xlabel('xlabel')
42+
if nn == 1:
43+
ax.set_ylabel('ylabel')
44+
subpanels[1].set_facecolor('0.85')
45+
subpanels[1].colorbar(pc, shrink=0.6, ax=axsRight)
46+
subpanels[1].suptitle('Right plots', fontsize='x-large')
47+
48+
fig.suptitle('Figure suptitle', fontsize='xx-large')
49+
50+
plt.show()

lib/matplotlib/figure.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
"""
22
`matplotlib.figure` implements the following classes:
33
4+
45
`Figure`
56
Top level `~matplotlib.artist.Artist`, which holds all plot elements.
7+
Many methods are implimented in `PanelBase`.
8+
9+
`SubPanel`
10+
A logical figure inside a figure, usually added to a figure or parent
11+
`SubPanel` with `.add_subpanel` or `.subpanels` methods.
612
713
`SubplotParams`
814
Control the default spacing between subplots.
@@ -221,7 +227,7 @@ def update(self, left=None, bottom=None, right=None, top=None,
221227
class PanelBase(Artist):
222228
"""
223229
Base class for `.figure.Figure` and `.figure.SubPanel` containing the
224-
methods that add artists to the figure, create axes, etc.
230+
methods that add artists to the figure or panel, create axes, etc.
225231
"""
226232
def __init__(self):
227233
super().__init__()
@@ -254,6 +260,7 @@ def __init__(self):
254260
self.panels = []
255261
self._suptitle = None
256262
self.stale = True
263+
self.suppressComposite = None
257264

258265
def _get_draw_artists(self, renderer):
259266
"""Also runs apply_aspect"""

0 commit comments

Comments
 (0)