4.1 多合一顯示
示意圖
plt.figure()
plt.subplot(2,2,1)#創(chuàng)建小圖
plt.plot([0,1],[0,1])
plt.subplot(2,2,1):分成2行2列保檐,現(xiàn)在在第一個(gè)位置開始畫圖
依次類推
plt.subplot(2,2,1)可以寫成plt.subplot(221)
-
在這一例中4個(gè)plt.subplot()中的數(shù)字分別是:
2,2,1
2,2,2
2,2,3
2,2,4
如果要做這種效果的話該怎么設(shè)置呢?
示意圖2 在這一例中4個(gè)plt.subplot()中的數(shù)字分別是:
2,1,1
2,3,4
2,3,5
2,3,6這種方法建議現(xiàn)在草稿上畫好圖框晦攒,標(biāo)好各框數(shù)字
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))
- ax1=plt.subplot2grid((3,3), (0,0),colspan=3,rowspan=1)
第一個(gè)括號里是表示這幅圖要幾行幾列
第二個(gè)括號是指這一張小圖的起始位置
colspan和rowspan表示這一張小圖的覆蓋范圍 - 在這一種方法中菊匿,對title凹蜈,坐標(biāo)等修改都改為形如:set_xxxx()
方法二: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])
- sharex=True, sharey=True共享x和y軸
- plt.subplots()要等于一個(gè)f棱诱,然后在f里面填入名字
- 接下來就可以用名字操控這些圖了