【问题标题】:How to plot linear fits for multiple plots in one graph?如何在一张图中绘制多个图的线性拟合?
【发布时间】:2021-02-22 20:28:15
【问题描述】:

我正在尝试为同一图中的三个图绘制线性最佳拟合线,以及它们各自的斜率和截距;我不知道该怎么做,所以它们都在我的数据中的同一张图中。有谁知道如何做到这一点? 我附上了一张图表如下所示的图片。

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()

【问题讨论】:

    标签: python numpy csv matplotlib


    【解决方案1】:

    您需要指定不为 0 的 xerr 和 yerr。 这些指定您希望沿 x 和 y 轴的误差条大小为多长时间。

    您也不必使用 subplots 和 ax,而是可以直接在 plt 上调用 errorbar,就像在此处的示例中一样:

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

    【讨论】:

      猜你喜欢
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      相关资源
      最近更新 更多