您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在Python中利用subplot 在一張畫布同時(shí)畫多張圖,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
arg1: 在垂直方向同時(shí)畫幾張圖
arg2: 在水平方向同時(shí)畫幾張圖
arg3: 當(dāng)前命令修改的是第幾張圖
plt.figure()另起一張新的畫布 from PIL import Image import matplotlib.pyplot as plt image1 = Image.open('1.jpg') image2 = Image.open('2.jpg') plt.subplot(121) plt.imshow(image1) plt.subplot(122) plt.imshow(image2) plt.show()
補(bǔ)充:matplotlib 同一個(gè)畫布繪制多張圖,主次刻度,豎線
我就廢話不多說了,大家還是直接看代碼吧~
import matplotlib.pyplot as plt import seaborn as sns sns.set() # 要分析的數(shù)據(jù) profit = df_profit.groupby('release_year')['profit'].agg(['mean','sum','count']) # 在同一個(gè)畫布中繪制兩張圖 plt.figure(figsize=(15,15)) # 圖一:每年上映電影的總收入 ax = plt.subplot(211) # 設(shè)置x軸 范圍 ax.set_xlim(1958,2018) # 設(shè)置x軸 主刻度,(次刻度設(shè)置minor=True) ax.set_xticks(np.arange(1960,2018,5), minor=False) # 畫圖 ax.plot(profit['sum'], linestyle='--', marker='o', markersize=5) ax.set_title('The Sum of Movies\' Revenue v.s. Release Year') ax.set_ylabel('Revenue(USD)') # 增加豎線 ax.axvline(x=1977, color='#d46061', linewidth=1); # 圖二:每年上映電影的平均收入 ax = plt.subplot(212) # 設(shè)置x軸 范圍 ax.set_xlim(1958,2018) # 設(shè)置x軸 主刻度 ax.set_xticks(np.arange(1960,2018,5)) # 畫圖 ax.plot(profit['mean'], linestyle='--', marker='o', markersize=5); ax.set_title('The Mean of Movies\' Revenue v.s. Release Year') ax.set_xlabel('Release Year') ax.set_ylabel('Revenue(USD)') # 增加豎線 ax.axvline(x=1977, color='#d46061', linewidth=1);
上述就是小編為大家分享的怎么在Python中利用subplot 在一張畫布同時(shí)畫多張圖了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。