Matplotlib系列—pyplot的子绘图区域
方法一
使用plt.subplot2grid( )来实现
plt.subplot2grid(GridSpec, CurSpec, colspan=1, rowspan=1)
思想:设定网格,选中网格,确定选中行列区域数量,编号从0开始
如上图所示:
- ax1:plt.subplot2grid((3,3),(1,0),colspan=2)
- ax3:plt.subplot2grid((3,3),(1,2),rowspan=2)
- ax4:plt.subplot2grid((3,3),(2,0))
方法二
使用Gridspec类来实现
导入:
import matplotlib.gridspec as gridspec
仍然使用上图的例子,则:
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
gs = gridspec.GridSpec(3,3)
ax1 = plt.subplot(gs[0,:])
#......
ax2 = plt.subplot(gs[1,:-1])
#......
ax3 = plt.subplot(gs[1:,-1])
#......
ax4 = plt.subplot(gs[2,0])
#......
ax5 = plt.subplot(gs[2,1])
#......
参考资料:北京理工大学嵩天老师教学视频