python - 如何为每个子图添加标题

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

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() 存在,但后者不会为我的子图添加任何标题。

感谢您的帮助。

编辑: 更正了关于 set_title() 的拼写错误。谢谢 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()

https://stackoverflow.com/questions/25239933/

相关文章:

python - 将 javadoc 用于 Python 文档

python - 从函数中获取文档字符串

linux - 在 Bash 中,如何在文件的每一行之后添加一个字符串?

linux - grep 的基本表达式不支持\d 吗?

python - 将 python 列表拆分为其他 "sublists"即较小的列表

linux - 如何从脚本编辑/etc/sudoers?

python - 尽管我调用了 pyplot.show(),但 matplotlib 没有显示我的情

linux - Linux bash 中波浪号的含义(不是主目录)

linux - 附加到进程输出以供查看

linux - dd:如何计算最佳 block 大小?