Note
Click here to download the full example code
Matplotlib alt text¶
This example tests that the alt text is generated correctly for matplotlib figures.
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1, constrained_layout=True)
axs[0].plot([1, 2, 3])
axs[0].set_title('subplot 1')
axs[0].set_xlabel('x label')
axs[0].set_ylabel('y lab')
fig.suptitle('This is a\nsup title')
axs[1].plot([2, 3, 4])
axs[1].set_title('subplot 2')
axs[1].set_xlabel('x label')
axs[1].set_ylabel('y label')
plt.show()

Out:
/home/lucy/Documents/sphinx-gallery/sphinx_gallery/tests/tinybuild/examples/plot_matplotlib_alt.py:24: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
Several titles.

Out:
/home/lucy/Documents/sphinx-gallery/sphinx_gallery/tests/tinybuild/examples/plot_matplotlib_alt.py:36: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
Total running time of the script: ( 0 minutes 0.318 seconds)