我使用创建了3个子图subplot()
.现在我想为每个子图添加标题.其中一个title()
和suptitle()
我应该使用?
一般来说,它们之间有什么区别?谢谢!
您可以设置与主图标题fig.suptitle
和次要情节与职称ax.set_title
或传递title
到fig.add_subplot
.例如:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-np.pi, np.pi, 0.01)
fig = plt.figure()
fig.suptitle('Main figure title')
ax1 = fig.add_subplot(311, title='Subplot 1 title')
ax1.plot(x, np.sin(x))
ax2 = fig.add_subplot(312)
ax2.set_title('Subplot 2 title')
ax2.plot(x, np.cos(x))
ax3 = fig.add_subplot(313)
ax3.set_title('Subplot 3 title')
ax3.plot(x, np.tan(x))
plt.show()
Run Code Online (Sandbox Code Playgroud)
(您可能需要手动调整字体大小以获得所需的样式).我认为字幕需要特殊的放置和文本大小.例如,请参阅在matplotlib中为图表提供字幕