Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add label to subplot in matplotlib

Is there an automatic way to add pure labels to the subplots? To be specific, I used

ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)

and I would like to add 'A' and 'B' to the upper right in the subplots to distinguish them, and right now I am using a dummy way something like

ax1.annotate('A', xy=(2, 1), xytext=(1, 22))
ax2.annotate('B', xy=(2, 1), xytext=(1, 22))

I tried using

ax1.legend()

and that also gives me "small images" of lines or dots before the letter and I do not need that image.

like image 229
GeauxEric Avatar asked Jun 09 '14 16:06

GeauxEric


1 Answers

You can skip writing a helper function and just call:

ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)

ax1.annotate("A", xy=(0.9, 0.9), xycoords="axes fraction")
ax2.annotate("B", xy=(0.9, 0.9), xycoords="axes fraction")
like image 193
Simas Glinskis Avatar answered Oct 04 '22 05:10

Simas Glinskis