How to place the suptitle rotated on the side of the figure
Question:
I’m working with Matplotlib in Python, and have the simple figure-suptitle layout shown below
Title
----------
|Figure |
|Pieces |
----------
The figure pieces are squished a bit, however. To make room, I would like to put the figure suptitle on the side, like so
----------
|Figure | (title rotated 90 degrees)
|Pieces |
----------
The reason I would like to do this is that there are 47 of these, and each will go on its own 8.5" x 11" page. An alternative would be to rotate the figure itself, although I imagine that might be harder.
Answers:
- Use the
rotation
parameter.
- See
matplotlib.pyplot.suptitle
& matplotlib.text.Text
for available parameters.
- This works for the explicit
Axes
interface, and for the implicit pyplot
interface.
- This answer also works for
seaborn
axes-level plots.
- Also see Improve subplot size/spacing with many subplots.
- Tested in
python 3.10
and matplotlib 3.5.2
import matplotlib.pyplot as plt
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
fig, ax = plt.subplots(3, 1, figsize=(3, 9))
ax[0].bar(names, values)
ax[1].scatter(names, values)
ax[2].plot(names, values)
fig.suptitle('Categorical Plotting', ha='right', va='center', x=1.1, y=0.5, rotation=270)
plt.show()
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting', ha='right', va='center', x=0.95, y=0.5, rotation=270)
plt.show()
I’m working with Matplotlib in Python, and have the simple figure-suptitle layout shown below
Title
----------
|Figure |
|Pieces |
----------
The figure pieces are squished a bit, however. To make room, I would like to put the figure suptitle on the side, like so
----------
|Figure | (title rotated 90 degrees)
|Pieces |
----------
The reason I would like to do this is that there are 47 of these, and each will go on its own 8.5" x 11" page. An alternative would be to rotate the figure itself, although I imagine that might be harder.
- Use the
rotation
parameter. - See
matplotlib.pyplot.suptitle
&matplotlib.text.Text
for available parameters.- This works for the explicit
Axes
interface, and for the implicitpyplot
interface.
- This works for the explicit
- This answer also works for
seaborn
axes-level plots. - Also see Improve subplot size/spacing with many subplots.
- Tested in
python 3.10
andmatplotlib 3.5.2
import matplotlib.pyplot as plt
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
fig, ax = plt.subplots(3, 1, figsize=(3, 9))
ax[0].bar(names, values)
ax[1].scatter(names, values)
ax[2].plot(names, values)
fig.suptitle('Categorical Plotting', ha='right', va='center', x=1.1, y=0.5, rotation=270)
plt.show()
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting', ha='right', va='center', x=0.95, y=0.5, rotation=270)
plt.show()