Adding text in multi-panel figures

This section describes how to align our text and put it on the figure object rather than the axis objects.

The following is the code for the two-axis figure, with a sine curve and a cosine curve seperated by spine:

# Figure textgs = mpl.gridspec.GridSpec(1,2, wspace=0.0)nums = np.arange(0,10,0.1)plt.subplot(gs[0])plt.plot(nums, np.sin(nums))plt.gca().spines['right'].set_visible(False)plt.gca().yaxis.set_ticks_position('left')plt.subplot(gs[1])plt.plot(nums, np.cos(nums))# plt.gca().yaxis.set_visible(False)# plt.gca().spines['left'].set_visible(False)plt.gca().xaxis.set_major_locator(mpl.ticker.MaxNLocator(5, prune='lower'))# plt.figtext(0.5,0.5, "trig functions", horizontalalignment='center')

To span the ...

Get Mastering Matplotlib 2.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.