Skip to content

Commit 96ff8f0

Browse files
committed
DOC
1 parent ebe0688 commit 96ff8f0

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
suplabelx and suplabely
2+
-----------------------
3+
4+
It is possible to add x and ylabels to a whole figure, analogous to
5+
`.FigureBase.suptitle` using the new `.FigureBase.supxlabel` and
6+
`.FigureBase.supylabel` methods.
7+
8+
.. plot::
9+
10+
fig, axs = plt.subplots(3, 2, figsize=(5, 5), constrained_layout=True,
11+
sharey=True, sharex=True)
12+
13+
for nn, ax in enumerate(axs.flat):
14+
ax.set_title(f'Channel {nn}')
15+
ax.plot(np.cumsum(np.random.randn(50)))
16+
17+
fig.supxlabel('Time [s]')
18+
fig.supylabel('Data [V]')

examples/subplots_axes_and_figures/figure_title.py

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""
2-
============
3-
Figure title
4-
============
2+
=============================================
3+
Figure labels: suptitle, supxlabel, supylabel
4+
=============================================
55
6-
Each subplot can have its own title (`.Axes.set_title`). Additionally,
7-
`.Figure.suptitle` adds a centered title at the top of the figure.
6+
Often it is desirable to have a title for a figure, while each subplot gets
7+
its own title using `.FigureBase.suptitle`.
8+
9+
We can also add figure-level supxlabel and supylabel
810
"""
11+
from matplotlib.cbook import get_sample_data
912
import matplotlib.pyplot as plt
13+
1014
import numpy as np
1115

1216

@@ -24,4 +28,36 @@
2428

2529
fig.suptitle('Different types of oscillations', fontsize=16)
2630

31+
##############################################################################
32+
# Note it is also sometimes useful to have a global x- or y-label, which
33+
# can be achieved with the `.FigureBase.supxlabel` and `.FigureBase.supylabel`
34+
# methods.
35+
36+
fig, axs = plt.subplots(3, 5, figsize=(8, 5), constrained_layout=True,
37+
sharey=True, sharex=True)
38+
39+
fname = get_sample_data('percent_bachelors_degrees_women_usa.csv',
40+
asfileobj=False)
41+
gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True)
42+
43+
majors = ['Health Professions', 'Public Administration', 'Education',
44+
'Psychology', 'Foreign Languages', 'English',
45+
'Art and Performance', 'Biology',
46+
'Agriculture', 'Business',
47+
'Math and Statistics', 'Architecture', 'Physical Sciences',
48+
'Computer Science', 'Engineering']
49+
50+
for nn, ax in enumerate(axs.flat):
51+
ax.set_xlim(1969.5, 2011.1)
52+
column = majors[nn]
53+
column_rec_name = column.replace('\n', '_').replace(' ', '_')
54+
55+
line, = ax.plot('Year', column_rec_name, data=gender_degree_data,
56+
lw=2.5)
57+
ax.set_title(column, fontsize='small', loc='left')
58+
ax.set_ylim([0, 100])
59+
ax.grid()
60+
fig.supxlabel('Year')
61+
fig.supylabel('Percent Degrees Awarded To Women')
62+
2763
plt.show()

0 commit comments

Comments
 (0)