subplot(numbRow , numbCol ,plotNum ) 或者 subplot(numbRow numbCol plotNum)
numbRow是plot图的行数;numbCol是plot图的列数;plotNum是指第几行第几列的第几幅图 ;位序从1开始。顺序是从左到右,从上到下 #画图-subplot把四个图放在一张图上 plt.figure(figsize=(15,15)) plt.subplot(2,2,1) #plt.plot()实际上会通过plt.gca()获得当前的Axes对象ax,然后再调用ax.plot()方法实现真正的绘图。 ax = plt.gca() plt.plot(rowData1,color = 'green') ax.set_xlabel('Pixel Number') ax.set_ylabel('Gray Value') ax.set_title("cameraman.tif's row") plt.subplot(2,2,2) ax = plt.gca() plt.plot(columnData1,color = 'red') ax.set_xlabel('Pixel Number') ax.set_ylabel('Gray Value') ax.set_title("cameraman.tif's column") plt.subplots_adjust(hspace = 0.5) plt.subplot(2,2,3) ax = plt.gca() plt.plot(rowData2,color = 'green') ax.set_xlabel('Pixel Number') ax.set_ylabel('Gray Value') ax.set_title("einstein.tif's row") plt.subplot(2,2,4) ax = plt.gca() plt.plot(columnData2,color = 'red') ax.set_xlabel('Pixel Number') ax.set_ylabel('Gray Value') ax.set_title("einstein.tif's column") plt.show()效果:
