1"""
2=============================================
3Figure labels: suptitle, supxlabel, supylabel
4=============================================
5
6Each axes can have a title (or actually three - one each with *loc* "left",
7"center", and "right"), but is sometimes desirable to give a whole figure
8(or `.SubFigure`) an overall title, using `.FigureBase.suptitle`.
9
10We can also add figure-level x- and y-labels using `.FigureBase.supxlabel` and
11`.FigureBase.supylabel`.
12"""
13from matplotlib.cbook import get_sample_data
14import matplotlib.pyplot as plt
15
16import numpy as np
17
18
19x = np.linspace(0.0, 5.0, 501)
20
21fig, (ax1, ax2) = plt.subplots(1, 2, constrained_layout=True, sharey=True)
22ax1.plot(x, np.cos(6*x) * np.exp(-x))
23ax1.set_title('damped')
24ax1.set_xlabel('time (s)')
25ax1.set_ylabel('amplitude')
26
27ax2.plot(x, np.cos(6*x))
28ax2.set_xlabel('time (s)')
29ax2.set_title('undamped')
30
31fig.suptitle('Different types of oscillations', fontsize=16)
32
33##############################################################################
34# A global x- or y-label can be set using the `.FigureBase.supxlabel` and
35# `.FigureBase.supylabel` methods.
36
37fig, axs = plt.subplots(3, 5, figsize=(8, 5), constrained_layout=True,
38                        sharex=True, sharey=True)
39
40fname = get_sample_data('percent_bachelors_degrees_women_usa.csv',
41                        asfileobj=False)
42gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True)
43
44majors = ['Health Professions', 'Public Administration', 'Education',
45          'Psychology', 'Foreign Languages', 'English',
46          'Art and Performance', 'Biology',
47          'Agriculture', 'Business',
48          'Math and Statistics', 'Architecture', 'Physical Sciences',
49          'Computer Science', 'Engineering']
50
51for nn, ax in enumerate(axs.flat):
52    ax.set_xlim(1969.5, 2011.1)
53    column = majors[nn]
54    column_rec_name = column.replace('\n', '_').replace(' ', '_')
55
56    line, = ax.plot('Year', column_rec_name, data=gender_degree_data,
57                    lw=2.5)
58    ax.set_title(column, fontsize='small', loc='left')
59    ax.set_ylim([0, 100])
60    ax.grid()
61fig.supxlabel('Year')
62fig.supylabel('Percent Degrees Awarded To Women')
63
64plt.show()
65