Matplotlib實(shí)現(xiàn)subplot和subplots簡(jiǎn)單對(duì)比
:
大家一般都知道subplot可以畫(huà)子圖,但是subplots也可以畫(huà)子圖,鑒于subplots介紹比較少,這里做一個(gè)對(duì)比,兩者沒(méi)有功能一致。
對(duì)比開(kāi)始:
需求:畫(huà)出兩張子圖,在一行顯示,子圖中的內(nèi)容一模一樣
subplot代碼:
ax1 = plt.subplot(1,2,1) ax1.scatter(positive['X1'], positive['X2'], s=50, marker='x', label='Positive') ax1.scatter(negative['X1'], negative['X2'], s=50, marker='o', label='Negative') ax1.legend()#添加圖列就是右上角的點(diǎn)說(shuō)明 ax2 = plt.subplot(1,2,2) ax2.scatter(positive['X1'], positive['X2'], s=50, marker='x', label='Positive') ax2.scatter(negative['X1'], negative['X2'], s=50, marker='o', label='Negative') ax2.legend()#添加圖列就是右上角的點(diǎn)說(shuō)明
subplots代碼:
fig, ax = plt.subplots(figsize=(12,8),ncols=2,nrows=1)#該方法會(huì)返回畫(huà)圖對(duì)象和坐標(biāo)對(duì)象ax,figsize是設(shè)置子圖長(zhǎng)寬(1200,800) ax[0].scatter(positive['X1'], positive['X2'], s=50, marker='x', label='Positive') ax[0].scatter(negative['X1'], negative['X2'], s=50, marker='o', label='Negative') ax[0].legend()#添加圖列就是右上角的點(diǎn)說(shuō)明 ax[1].scatter(positive['X1'], positive['X2'], s=50, marker='x', label='Positive') ax[1].scatter(negative['X1'], negative['X2'], s=50, marker='o', label='Negative') ax[1].legend()#添加圖列就是右上角的點(diǎn)說(shuō)明
對(duì)比結(jié)果:
可以看出來(lái)兩者都可以實(shí)現(xiàn)畫(huà)子圖功能,只不過(guò)subplots幫我們把畫(huà)板規(guī)劃好了,返回一個(gè)坐標(biāo)數(shù)組對(duì)象,而subplot每次只能返回一個(gè)坐標(biāo)對(duì)象,subplots可以直接指定畫(huà)板的大小。
參考博客:Matplotlib的子圖subplot的使用
參考博客:subplots與figure函數(shù)參數(shù)解釋說(shuō)明以及簡(jiǎn)單的使用腳本實(shí)例
到此這篇關(guān)于Matplotlib實(shí)現(xiàn)subplot和subplots簡(jiǎn)單對(duì)比的文章就介紹到這了,更多相關(guān)Matplotlib subplot和subplots內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。