Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put text between plots in matplotlib

I have a grid of plots using matplotlib, and want text to be between two of the plots. Here is my code:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(3,3, figsize = (14,8))
ax[0,0].set_title('(0,0)')
ax[0,1].set_title('(0,1)')
ax[0,2].set_title('(0,2)')
ax[1,0].set_title('(1,0)')
ax[1,1].set_title('(1,1)')
ax[1,2].set_title('(1,2)')
ax[2,0].set_title('(2,0)')
ax[2,1].set_title('(2,1)')
ax[2,2].set_title('(2,2)')
info = 'A = {}'.format(1)
ax[0,1].text(1.2,0.5,info)
fig.tight_layout()
plt.show()

which prints this:

enter image description here

What I want is there to be text between plots (0,1) and (0,2). Is there a way to do this?

like image 340
TheStrangeQuark Avatar asked Apr 11 '26 00:04

TheStrangeQuark


1 Answers

Yes you can use Matplotlibs text.Text classs

You will need to set the x and y values to correspond the middle of the right axes of the plot you want to add the text for and you can use verticalalignment and horizontalalignment to place the text where you want.

See some examples here.

Hope this helps.

like image 54
EngineerCamp Avatar answered Apr 12 '26 15:04

EngineerCamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!