Python plt 利用subplot 實(shí)現(xiàn)在一張畫(huà)布同時(shí)畫(huà)多張圖
arg1: 在垂直方向同時(shí)畫(huà)幾張圖
arg2: 在水平方向同時(shí)畫(huà)幾張圖
arg3: 當(dāng)前命令修改的是第幾張圖
plt.figure()另起一張新的畫(huà)布from PIL import Imageimport matplotlib.pyplot as pltimage1 = 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è)畫(huà)布繪制多張圖,主次刻度,豎線
我就廢話不多說(shuō)了,大家還是直接看代碼吧~
import matplotlib.pyplot as pltimport seaborn as snssns.set()# 要分析的數(shù)據(jù)profit = df_profit.groupby(’release_year’)[’profit’].agg([’mean’,’sum’,’count’])# 在同一個(gè)畫(huà)布中繪制兩張圖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)# 畫(huà)圖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))# 畫(huà)圖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);
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章:
1. vue跳轉(zhuǎn)頁(yè)面常用的幾種方法匯總2. 不要在HTML中濫用div3. ASP 處理JSON數(shù)據(jù)的實(shí)現(xiàn)代碼4. js開(kāi)發(fā)中的頁(yè)面、屏幕、瀏覽器的位置原理(高度寬度)說(shuō)明講解(附圖)5. CSS清除浮動(dòng)方法匯總6. XML 非法字符(轉(zhuǎn)義字符)7. ASP動(dòng)態(tài)include文件8. 父div高度不能自適應(yīng)子div高度的解決方案9. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)10. XML入門(mén)的常見(jiàn)問(wèn)題(三)
