Reputation:
Suppose I have a set of data points which I want to plot with matplotlib
and Python 3
. However, these points are better understood if some additional information (or metadata) are added. This metadata is simply text.
Is there a way to print a figure in which there's some space reserved for such text data? (see fig. for example)
Upvotes: 1
Views: 2652
Reputation: 6472
An alternative way to do it is to create your figure and axes, hide one of the axes, but still use it's text
method to place your metadata. This method uses plot coordinates, for example to get centered text, this:
fig, ax = plt.subplots(2,1)
ax[1].axis('off')
ax[1].text(0.5, 0.5, 'Your-plot-metadata', ha='center', va='center')
will produce:
with the text centered on the hidden axes. If you want to change the proportion of these plots, have a look at gridspec
.
I know matplotlib also supports tables if that works better than ax.text()
for you.
Upvotes: 0
Reputation: 69106
You can add some space at the bottom of the figure using subplots_adjust(bottom=0.3)
(or whatever value of bottom
works for you).
Then add text in the space below with fig.text
.
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)
fig.subplots_adjust(bottom=0.3)
ax.plot(range(10))
fig.text(0.1,0.20,'Temp: 77K')
fig.text(0.1,0.15,'V_1: 22.4V')
fig.text(0.1,0.10,'V_1: 22.4V')
fig.text(0.1,0.05,'pump: 1064nm')
plt.show()
Upvotes: 2