python繪圖subplots函數(shù)使用模板的示例代碼
背景
使用python進(jìn)行圖像可視化,很多情況下都需要subplots將多幅圖像繪制在一個(gè)figure中。因?yàn)槭褂妙l率足夠高,那么程序員就需要將其“封裝”,方便復(fù)用,所以,這里將筆者常用的subplots用法記錄之。
如果有python繪圖使用subplots出現(xiàn)標(biāo)題重疊的解決方法 的問(wèn)題,可以參考之。
模板
顯示中文
plt.rcParams['font.sans-serif'] = ['SimHei'] # 顯示中文
使用subplot(221)

對(duì)應(yīng)的subplots代碼:
from skimage import data
from matplotlib import pyplot as plt
moon = data.moon()
camera = data.camera()
image_minus = moon - camera
image_plus = moon + camera
# 繪圖
plt.rcParams['font.sans-serif'] = ['SimHei'] # 顯示中文
plt.subplot(2, 2, 1)
plt.title('月亮圖像')
plt.imshow(moon)
plt.subplot(2, 2, 2)
plt.title('攝影師圖像')
plt.imshow(camera)
plt.subplot(2, 2, 3)
plt.title('月亮加攝影師圖像')
plt.imshow(image_plus)
plt.subplot(2, 2, 4)
plt.title('月亮減攝影師圖像')
plt.imshow(image_minus)
plt.tight_layout()
plt.show()
使用subplots(2,2) 配合axs

對(duì)應(yīng)的subplots代碼
from skimage import data
from matplotlib import pyplot as plt
moon = data.moon()
camera = data.camera()
image_minus = moon - camera
image_plus = moon + camera
# 繪圖
plt.rcParams['font.sans-serif'] = ['SimHei'] # 顯示中文
fig, axs = plt.subplots(2, 2)
axs[0, 0].imshow(moon)
axs[0, 0].set_title("月亮圖像")
axs[0, 1].imshow(camera)
axs[0, 1].set_title("攝影師圖像")
axs[1, 0].imshow(image_plus)
axs[1, 0].set_title("月亮加攝影師圖像")
axs[1, 1].imshow(image_minus)
axs[1, 1].set_title("月亮減攝影師圖像")
plt.tight_layout() # 子圖之間合理間距
plt.show() # 顯示圖像
到此這篇關(guān)于python繪圖subplots函數(shù)使用模板的示例代碼的文章就介紹到這了,更多相關(guān)python繪圖subplots函數(shù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python中的內(nèi)置函數(shù)max()和min()及mas()函數(shù)的高級(jí)用法
- python print()函數(shù)的end參數(shù)和sep參數(shù)的用法說(shuō)明
- python處理emoji表情(兩個(gè)函數(shù)解決兩者之間的聯(lián)系)
- 解決python2中unicode()函數(shù)在python3中報(bào)錯(cuò)的問(wèn)題
- python-opencv中的cv2.inRange函數(shù)用法說(shuō)明
- Python input()函數(shù)用法大全
- python Pool常用函數(shù)用法總結(jié)
- python 如何用map()函數(shù)創(chuàng)建多線程任務(wù)
- Python函數(shù)參數(shù)中的*與**運(yùn)算符
- 詳解python函數(shù)傳參傳遞dict/list/set等類型的問(wèn)題
- Python3去除頭尾指定字符的函數(shù)strip()、lstrip()、rstrip()用法詳解
- Python進(jìn)階之高級(jí)用法詳細(xì)總結(jié)
相關(guān)文章
python中pop()函數(shù)的語(yǔ)法與實(shí)例
這篇文章主要給大家介紹了關(guān)于python中pop()函數(shù)語(yǔ)法與實(shí)例的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
使用Pygal庫(kù)創(chuàng)建可縮放的矢量圖表的操作方法
在本文中,我們探討了如何使用Pygal庫(kù)創(chuàng)建可縮放的矢量圖表,首先,我們介紹了Pygal的基本概念和安裝方法,然后通過(guò)多個(gè)示例演示了如何創(chuàng)建各種類型的圖表,包括折線圖、柱狀圖、餅圖、散點(diǎn)圖、雷達(dá)圖和地圖等,需要的朋友可以參考下2024-05-05
python中datetime模塊中strftime/strptime函數(shù)的使用
這篇文章主要介紹了python中datetime模塊中strftime/strptime函數(shù)的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
Python中對(duì)數(shù)組集進(jìn)行按行打亂shuffle的方法
今天小編就為大家分享一篇Python中對(duì)數(shù)組集進(jìn)行按行打亂shuffle的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-11-11

