python - 如何在一张图中绘制多个图的线性拟合?
问题描述
我正在尝试为同一图中的三个图绘制线性最佳拟合线,以及它们各自的斜率和截距;我不知道该怎么做,所以它们都在我的数据中的同一张图中。有谁知道如何做到这一点?我附上了一张图表在下面的样子。
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 轴的误差条大小为多长时间。
您也不必使用 subplots 和 ax 而是可以直接在 plt 上调用 errorbar ,就像在此处的示例中一样:
https://matplotlib.org/3.3.2/gallery/lines_bars_and_markers/errorbar_limits_simple.html
推荐阅读
- python - Django:解决“找不到'password_reset_complete'的反向。”
- symfony - Symfony 服务 FileUploader 不自动装配
- javascript - 使用 v-for 时出现问题。带点的道具不显示
- python - 使用归一化迭代计数的 Mandelbrot 集
- javascript - 如何更新 Mobx 可观察数组中的对象
- javascript - 如何在开发中的任何路线上提供 HtmlWebpackPlugin 的 index.html 版本?
- flutter - Flutter DiagnosticableTreeMixin 与 @freezed
- python - 代码太慢 USACO Bronze 2015 问题 1 python
- c++ - lang 格式中 RawStringFormats 和 Demeters 'pb' 的含义
- git - Git 从历史记录中删除合并提交,但保留已连接的提交