本篇內容主要講解“怎么使用Python+matplotlib實現循環作圖”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“怎么使用Python+matplotlib實現循環作圖”吧!
原始代碼,如下所示:
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")
# 設置畫布
fig = plt.figure(figsize=(20, 8)) # figsize是常用的參數.(寬,高)
axl = fig.add_subplot(1, 1, 1)
for i in range(len(result_parameter_peak)):
x = np.arange(0, 400, 1)
# 繪制gamma曲線
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")
# 設置坐標軸標題
axl.set_xlabel('Time')
axl.set_ylabel('Probility')
axl.set_title('分布')
# 可視化
plt.show()得到的只是單個的圖。

示例代碼:
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曲線
y661 = st.gamma.pdf(x, alpha, scale=beta)
plt.plot(x, y661, '-.')
# 設置坐標軸標題
plt.xlabel('Time')
plt.ylabel('Probility')
plt.title('分布')
# 可視化
plt.show()運行之后,結果如下圖所示:

給圖加了圖注,看上去高大上一些,代碼如下所示:
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曲線
y661 = st.gamma.pdf(x, alpha, scale=beta)
# plt.plot(x, y661, '-.')
plt.plot(x, y661, '-.', label="α:" + str(alpha) + "β:" + str(beta))
# 設置坐標軸標題
plt.xlabel('Time')
plt.ylabel('Probility')
plt.title('fenbu')
# 可視化
plt.legend()
plt.show()得到的效果圖如下所示:

到此,相信大家對“怎么使用Python+matplotlib實現循環作圖”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。