如何在Matplotlib中的子图中添加标题? [英] How to add title to subplots in Matplotlib?

查看:3908
本文介绍了如何在Matplotlib中的子图中添加标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多子图的图形.

I have one figure which contains many subplots.

fig = plt.figure(num=None, figsize=(26, 12), dpi=80, facecolor='w', edgecolor='k')
fig.canvas.set_window_title('Window Title')

# Returns the Axes instance
ax = fig.add_subplot(311) 
ax2 = fig.add_subplot(312) 
ax3 = fig.add_subplot(313) 

如何为子图添加标题?

fig.suptitle为所有图形添加标题,尽管ax.set_title()存在,但后者未向我的子图添加任何标题.

fig.suptitle adds a title to all graphs and although ax.set_title() exists, the latter does not add any title to my subplots.

谢谢您的帮助.

纠正了有关set_title()的错字.感谢Rutger Kassies

Corrected typo about set_title(). Thanks Rutger Kassies

推荐答案

ax.title.set_text('My Plot Title')似乎也可以.

fig = plt.figure()
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)
ax1.title.set_text('First Plot')
ax2.title.set_text('Second Plot')
ax3.title.set_text('Third Plot')
ax4.title.set_text('Fourth Plot')
plt.show()

这篇关于如何在Matplotlib中的子图中添加标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆