【python】Matplotlib入门(三)

2020-09-15  本文已影响0人  虫虫工工队

4.1 多合一显示

示意图
plt.figure()
plt.subplot(2,2,1)#创建小图
plt.plot([0,1],[0,1])

4.2 多合一显示2

方法一:subplot2grid

import matplotlib.gridspec as gridspec


方法1
plt.figure()
ax1=plt.subplot2grid((3,3), (0,0),colspan=3,rowspan=1)
ax1.plot([1,2], [1,2])
ax1.set_title('ax1_title')

ax2=plt.subplot2grid((3,3), (1,0),colspan=2)
ax3=plt.subplot2grid((3,3), (1,2),rowspan=2)
ax4=plt.subplot2grid((3,3), (2,0))
ax5=plt.subplot2grid((3,3), (2,1))

方法二:gridspec

import matplotlib.gridspec as gridspec

plt.figure()
gs=gridspec.GridSpec(3,3)
ax1=plt.subplot(gs[0,:])
ax2=plt.subplot(gs[1,:2])
ax3=plt.subplot(gs[1:,2])
ax4=plt.subplot(gs[-1,0])
ax5=plt.subplot(gs[-1,-2])
同样得到这张图

方法三:easy to define structure

f,((ax11,ax12),(ax21,ax22))=plt.subplots(2,2, sharex=True, sharey=True)
ax11.scatter([1,1],[2,2])
上一篇 下一篇

猜你喜欢

热点阅读