欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Matplotlib子图相关操作

程序员文章站 2022-03-01 22:18:09
...
# 准备画布
fig = plt.figure()
# 添加子图 2 * 2 的第1张图
ax1 = fig.add_subplot(221)
# 添加子图 2 * 2 的第2张图
ax2 = fig.add_subplot(222)
# 添加子图 2 * 2 的第3张图
ax3 = fig.add_subplot(223)
# 添加子图 2 * 2 的第4张图
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')

# 设置子图边距和间隔
left  = 0.125  # the left side of the subplots of the figure
right = 0.9    # the right side of the subplots of the figure
bottom = 0.1   # the bottom of the subplots of the figure
top = 0.9      # the top of the subplots of the figure
wspace = 0.2   # the amount of width reserved for blank space between subplots,
               # expressed as a fraction of the average axis width
hspace = 0.2   # the amount of height reserved for white space between subplots,
               # expressed as a fraction of the average axis height

plt.subplots_adjust(left=left, bottom=bottom, right=right, top=top,
                wspace=wspace, hspace=hspace)
# 展示
plt.show()