我有一个包含许多子图的图。
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
发布于 2016-08-25 05:57:09
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()

发布于 2014-08-11 20:15:27
ax.set_title()应该为单独的子图设置标题:
import matplotlib.pyplot as plt
if __name__ == "__main__":
data = [1, 2, 3, 4, 5]
fig = plt.figure()
fig.suptitle("Title for whole figure", fontsize=16)
ax = plt.subplot("211")
ax.set_title("Title for first plot")
ax.plot(data)
ax = plt.subplot("212")
ax.set_title("Title for second plot")
ax.plot(data)
plt.show()你能检查一下这段代码是否适合你吗?也许以后会有什么东西覆盖它们?
发布于 2017-12-15 17:04:25
假设为import matplotlib.pyplot as plt的简写答案
plt.gca().set_title('title')如下所示:
plt.subplot(221)
plt.gca().set_title('title')
plt.subplot(222)
etc...这样就不需要多余的变量了。
https://stackoverflow.com/questions/25239933
复制相似问题