matploylib_subplot

matplotlib 是可以組合許多的小圖, 放在一張大圖里面顯示的. 使用到的方法叫作 subplot.


Demo.py

import matplotlib.pyplot as plt
#figure1
plt.figure()
plt.subplot(2,2,1)
plt.plot([0,1],[0,1])
plt.subplot(2,2,2)
plt.plot([0,1],[0,2])
plt.subplot(223)
plt.plot([0,1],[0,3])
plt.subplot(224)
plt.plot([0,1],[0,4])

plt.show()  # 展示

import matplotlib.pyplot as plt
#figure2
plt.subplot(2,1,1)
plt.plot([0,1],[0,1])
#這里需要解釋一下為什么第4個(gè)位置放第2個(gè)小圖. 
#上一步中使用plt.subplot(2,1,1)將整個(gè)圖像窗口分為2行1列, 第1個(gè)小圖占用了第1個(gè)位置, 
#也就是整個(gè)第1行. 這一步中使用plt.subplot(2,3,4)將整個(gè)圖像窗口分為2行3列, 
#于是整個(gè)圖像窗口的第1行就變成了3列, 也就是成了3個(gè)位置, 
#于是第2行的第1個(gè)位置是整個(gè)圖像窗口的第4個(gè)位置.
#使用plt.subplot(235)將整個(gè)圖像窗口分為2行3列,當(dāng)前位置為5. 使用plt.plot([0,1],[0,3])在第5個(gè)位置創(chuàng)建一個(gè)小圖. 同上, 再創(chuàng)建plt.subplot(236)
plt.subplot(2,3,4)
plt.plot([0,1],[0,2])
plt.subplot(235)
plt.plot([0,1],[0,3])
plt.subplot(236)
plt.plot([0,1],[0,4])

plt.show()  # 展示

結(jié)果:

Paste_Image.png
Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容