簡體   English   中英

如何在一張圖中繪制多個圖的線性擬合?

[英]How to plot linear fits for multiple plots in one graph?

我正在嘗試為同一圖中的三個圖繪制線性最佳擬合線,以及它們各自的斜率和截距; 我不知道該怎么做,所以它們都在我的數據的同一個圖中。 有誰知道如何做到這一點? 我附上了一張圖表如何在下面顯示的圖像。

CSVfile_1 = 'Gas01_Fast.csv'
V_1, T_1, P_1, t_1 = getVTPt(filename='Gas01_Fast.csv')

CSVfile_2 = 'Gas02_Fast.csv'
V_2, T_2, P_2, t_2 = getVTPt(filename='Gas02_Fast.csv')

CSVfile_3 = 'Gas03_Fast.csv'
V_3, T_3, P_3, t_3 = getVTPt(filename='Gas03_Fast.csv')


fig, ax = plt.subplots()

ax.set_xlabel("Log(Volume)")
ax.set_ylabel("Log(Pressure)")
ax.set_title("Log(Pressure) vs Log(Volume)")


ax.errorbar(x=np.log10(V_1),y=np.log10(P_1),xerr=0,yerr=0,fmt='ro', ms=3)

ax.errorbar(x=np.log10(V_2),y=np.log10(P_2),xerr=0,yerr=0, fmt='bo', ms=3)

ax.errorbar(x=np.log10(V_3),y=np.log10(P_3),xerr=0,yerr=0, fmt='go', ms=3)

plt.legend(["Gas01_Fast.csv", "Gas02_Fast.csv","Gas03_Fast.csv"])

plt.show()

由上述代碼制作的圖形圖像

您需要指定不同於 0 的 xerr 和 yerr。它們指定您希望沿 x 軸和 y 軸的誤差條大小的長度。

您也不必使用子圖和 ax,而是可以直接在 plt 上調用 errorbar ,就像在此處的示例中一樣:

https://matplotlib.org/3.3.2/gallery/lines_bars_and_markers/errorbar_limits_simple.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM