Get the title of a given figure
There seems to be no public API to access this. But with some cautions you could use the non-public / potentially instable members:
fig._suptitle.get_text()
Another solution would be to use fig.texts
which returns a list of matplotlib.text.Text
objects. Therefore, we can get the first element of the list, then use get_text()
to get the actual title:
fig = plt.figure()
fig.suptitle("my title")
text = fig.texts[0].get_text()
print(text)
# my title
You can get the title through the axes:
fig.axes[0].get_title()
In case you have access to the axis itself, you can directly do:
ax.get_title()