如何在matplotlib中在图之间放置文本

2024-04-20 12:37:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用matplotlib的绘图网格,希望文本位于两个绘图之间。这是我的代码:

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()

打印这个:

enter image description here

我想要的是在绘图(0,1)和(0,2)之间有文本。有办法吗?在


Tags: 代码文本importinfo网格绘图titlematplotlib
1条回答
网友
1楼 · 发布于 2024-04-20 12:37:48

是的,您可以使用Matplotlibs text.Text classs

您需要设置x和y值,使其与要添加文本的绘图的右轴的中间相对应,并且可以使用verticalalignmenthorizontalalignment将文本放在所需的位置。在

some examples here。在

希望这有帮助。在

相关问题 更多 >