ZR-
ZR-

Reputation: 819

How can I determine the position of my subplot label?

I'm trying to label both of my subplots using Python and locate the text to the upper right corner:

fig, axs = plt.subplots(2, sharex=True, figsize = (16,18))
plt.xticks(fontsize=15)
...
axs[0].text(0.9,0.1,r'$E_b$',verticalalignment='top',fontsize = 30)

The last line is referenced from matplotlib.axes.Axes.text . I've read some examples but I'm still not pretty sure how I can determine the appropriate values of x and y to make my label to the upper right corner? The current values (0,9 and 0.1) do not work.

Upvotes: 0

Views: 105

Answers (1)

Karina
Karina

Reputation: 1280

Doing this:

fig, axs = plt.subplots(2, sharex=True, figsize = (16,18))
plt.xticks(fontsize=15)

plt.text(0.67, 0.9, 'I am 0.70, 0.90', fontsize=14, transform=plt.gcf().transFigure)
plt.text(0.67, 0.48, 'I am 0.70, 0.48', fontsize=14, transform=plt.gcf().transFigure)

Will give you this: enter image description here

axs[0].text(...)

will give you the text coordinate relative to axs[0]. I guess what you want is to have figure coordinate instead of axis coordinate. For that you need

transform=plt.gcf().transFigure

and just plt.text(...) so you don't need to specify the subplots.

Figure coordinate 0,0 is bottom left and 1,1 is upper right.

Upvotes: 1

Related Questions