溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Matplotlib的subplot和subplots怎么使用

發(fā)布時間:2022-02-25 16:42:36 來源:億速云 閱讀:154 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Matplotlib的subplot和subplots怎么使用的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇Matplotlib的subplot和subplots怎么使用文章都會有所收獲,下面我們一起來看看吧。

對比開始:

需求:畫出兩張子圖,在一行顯示,子圖中的內(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()#添加圖列就是右上角的點說明
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()#添加圖列就是右上角的點說明

subplots代碼

fig, ax = plt.subplots(figsize=(12,8),ncols=2,nrows=1)#該方法會返回畫圖對象和坐標對象ax,figsize是設(shè)置子圖長寬(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()#添加圖列就是右上角的點說明
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()#添加圖列就是右上角的點說明

對比結(jié)果:

可以看出來兩者都可以實現(xiàn)畫子圖功能,只不過subplots幫我們把畫板規(guī)劃好了,返回一個坐標數(shù)組對象,而subplot每次只能返回一個坐標對象,subplots可以直接指定畫板的大小。

關(guān)于“Matplotlib的subplot和subplots怎么使用”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“Matplotlib的subplot和subplots怎么使用”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI