Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatically position text box in matplotlib

Is there a way of telling pyplot.text() a location like you can with pyplot.legend()?

Something like the legend argument would be excellent:

plt.legend(loc="upper left") 

I am trying to label subplots with different axes using letters (e.g. "A","B"). I figure there's got to be a better way than manually estimating the position.

Thanks

like image 832
Anake Avatar asked Aug 12 '11 20:08

Anake


1 Answers

Just use annotate and specify axis coordinates. For example, "upper left" would be:

plt.annotate('Something', xy=(0.05, 0.95), xycoords='axes fraction') 

You could also get fancier and specify a constant offset in points:

plt.annotate('Something', xy=(0, 1), xytext=(12, -12), va='top'              xycoords='axes fraction', textcoords='offset points') 

For more explanation see the examples here and the more detailed examples here.

like image 184
Joe Kington Avatar answered Oct 06 '22 14:10

Joe Kington