Python+matplotlib實(shí)現(xiàn)循環(huán)作圖的方法詳解
大家好,我是皮皮。
一、前言
前幾天在Python白銀交流群【在 途中要勤奮的熏肉肉】問(wèn)了一道Python可視化處理的問(wèn)題,如下圖所示。

原始代碼,如下所示:
import?pandas?as?pd
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?scipy.stats?as?st
result_parameter_peak?=?pd.read_csv("result_parameter_peak.csv",?encoding="utf_8_sig")
#?設(shè)置畫(huà)布
fig?=?plt.figure(figsize=(20,?8))??#?figsize是常用的參數(shù).(寬,高)
axl?=?fig.add_subplot(1,?1,?1)
for?i?in?range(len(result_parameter_peak)):
????x?=?np.arange(0,?400,?1)
????#?繪制gamma曲線(xiàn)
????y661?=?st.gamma.pdf(x,?result_parameter_peak.iloc[i,?1],?scale=result_parameter_peak.iloc[i,?2])
????axl.plot(x,?y661,?'r-.',?label="α=?9.9028,β=10.4205")
????#?設(shè)置坐標(biāo)軸標(biāo)題
????axl.set_xlabel('Time')
????axl.set_ylabel('Probility')
????axl.set_title('分布')
????#?可視化
????plt.show()
得到的只是單個(gè)的圖。

二、實(shí)現(xiàn)過(guò)程
這里【月神】給了一個(gè)思路和一份示例代碼,如下所示:

import?pandas?as?pd
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?scipy.stats?as?st
result_parameter_peak?=?pd.read_csv("result_parameter_peak.csv",?encoding="utf_8_sig")
plt.figure()
for?i,?alpha,?beta?in?result_parameter_peak.itertuples():
????x?=?np.arange(0,?300,?1)
????#?繪制gamma曲線(xiàn)
????y661?=?st.gamma.pdf(x,?alpha,?scale=beta)
????plt.plot(x,?y661,?'-.')
????#?設(shè)置坐標(biāo)軸標(biāo)題
????plt.xlabel('Time')
????plt.ylabel('Probility')
????plt.title('分布')
#?可視化
plt.show()
運(yùn)行之后,結(jié)果如下圖所示:

順利地解決了粉絲的問(wèn)題!

后來(lái)【小趴菜】又給圖加了圖注,看上去高大上一些,代碼如下所示:
import?pandas?as?pd
import?numpy?as?np
import?matplotlib.pyplot?as?plt
import?scipy.stats?as?st
result_parameter_peak?=?pd.read_csv("result_parameter_peak.csv",?encoding="utf_8_sig")
plt.figure()
for?i,?alpha,?beta?in?result_parameter_peak.itertuples():
????x?=?np.arange(0,?300,?1)
????#?繪制gamma曲線(xiàn)
????y661?=?st.gamma.pdf(x,?alpha,?scale=beta)
????#?plt.plot(x,?y661,?'-.')
????plt.plot(x,?y661,?'-.',?label="α:"?+?str(alpha)?+?"β:"?+?str(beta))
????#?設(shè)置坐標(biāo)軸標(biāo)題
????plt.xlabel('Time')
????plt.ylabel('Probility')
????plt.title('fenbu')
????
#?可視化
plt.legend()
plt.show()
得到的效果圖如下所示:

三、總結(jié)
大家好,我是皮皮。這篇文章主要盤(pán)點(diǎn)了一道matplotlib作圖的問(wèn)題,文中針對(duì)該問(wèn)題給出了具體的解析和代碼實(shí)現(xiàn),幫助粉絲順利解決了問(wèn)題。
到此這篇關(guān)于Python+matplotlib實(shí)現(xiàn)循環(huán)作圖的方法詳解的文章就介紹到這了,更多相關(guān)Python matplotlib循環(huán)作圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中使用Inotify監(jiān)控文件實(shí)例
這篇文章主要介紹了Python中使用Inotify監(jiān)控文件實(shí)例,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-02-02
python小數(shù)字符串轉(zhuǎn)數(shù)字的五種方法
本文主要介紹了python小數(shù)字符串轉(zhuǎn)數(shù)字的五種方法,根據(jù)具體需求選擇合適的方法進(jìn)行小數(shù)字符串轉(zhuǎn)數(shù)字,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
python 解決Fatal error in launcher:錯(cuò)誤問(wèn)題
這篇文章主要介紹了python 解決Fatal error in launcher:錯(cuò)誤問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
python GUI庫(kù)圖形界面開(kāi)發(fā)之PyQt5打印控件QPrinter詳細(xì)使用方法與實(shí)例
這篇文章主要介紹了python GUI庫(kù)圖形界面開(kāi)發(fā)之PyQt5打印控件QPrinter詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下2020-02-02
django models里數(shù)據(jù)表插入數(shù)據(jù)id自增操作
這篇文章主要介紹了django models里數(shù)據(jù)表插入數(shù)據(jù)id自增操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
Pandas?Groupby之在Python中匯總、聚合和分組數(shù)據(jù)的示例詳解
GroupBy是一個(gè)非常簡(jiǎn)單的概念,我們可以創(chuàng)建一個(gè)類(lèi)別分組,并對(duì)這些類(lèi)別應(yīng)用一個(gè)函數(shù),本文給大家介紹Pandas?Groupby之如何在Python中匯總、聚合和分組數(shù)據(jù),感興趣的朋友跟隨小編一起看看吧2023-07-07
詳解Python中如何寫(xiě)控制臺(tái)進(jìn)度條的整理
這篇文章主要介紹了詳解Python中如何寫(xiě)控制臺(tái)進(jìn)度條的整理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03

