第一种多图显示方法:
代码:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import gridspec
plt.figure('第一种方法')
plt.subplot(2,2,1)
plt.plot([0,1],[0,1])
plt.subplot(2,2,2)
plt.plot([0,1],[0,1])
plt.subplot(2,2,3)
plt.plot([0,1],[0,1])
plt.subplot(2,2,4)
plt.plot([0,1],[0,1])
plt.show()
法一效果图:
第二种多图显示方法:
import matplotlib.pyplot as plt
plt.figure('第二种方法')
plt.subplot(2,1,1)
plt.plot([0,1],[0,1])
plt.subplot(2,3,4)
plt.plot([0,1],[0,1])
plt.subplot(2,3,5)
plt.plot([0,1],[0,1])
plt.subplot(2,3,6)
plt.plot([0,1],[0,1])
plt.show()
法二效果图:
第三种多图显示方法:
import matplotlib.pyplot as plt
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,rowspan=1)
ax2.set_title('ax2_title')
ax3 = plt.subplot2grid((3,3),(1,2),rowspan=2)
ax4 = plt.subplot2grid((3,3),(2,0))
ax5 = plt.subplot2grid((3,3),(2,1))
plt.show()
subplot2grid(总份数,左上角起始点,占用列数(默认为1),占用行数(默认为1))
法三效果图:
第四种多图显示方法:
此种方法引用了matplotlib模块中的gridspec部分
代码:
import matplotlib.pyplot as plt
from matplotlib import 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])
plt.show()
法四效果图:
第五种多图显示方法:
代码:
import matplotlib.pyplot as plt
f,((ax11,ax12),(ax21,ax22))=plt.subplots(2,2,sharex='all',sharey='all') #不是ture
ax11.plot([1,2],[1,2])
ax12.scatter([1,2],[1,2])
ax21.scatter([1,2],[1,2])
ax22.plot([1,2],[1,2])
plt.show()
法五效果图:
综合多种方法,个人认为方法三是比较方便的。