automatically position text box in matplotlib

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)