本文主要是介绍Matplotlib子图相关操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# 准备画布
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 heightplt.subplots_adjust(left=left, bottom=bottom, right=right, top=top,wspace=wspace, hspace=hspace)
# 展示
plt.show()
这篇关于Matplotlib子图相关操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!