TheStrangeQuark
TheStrangeQuark

Reputation: 2405

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?

Upvotes: 3

Views: 3292

Answers (1)

EngineerCamp
EngineerCamp

Reputation: 671

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.

Upvotes: 1

Related Questions