Skip to main content
 首页 » 编程设计

python之具有对数 Y 轴的小平面网格上的线性回归线

2024年10月24日9xiaohuochai

我的代码完全按照我的意愿工作:它绘制了两个彩色数据集,TypeA 和 TypeB,在由值 Divison 分隔的三个图上> 只有 Y 的对数轴。

pal = dict(TypeA="seagreen", TypeB="gray") 
g = sns.FacetGrid(df, hue="Source", col='Division', palette=pal, size=5) 
g.map(plt.scatter, "X_Data", "Y_LogData") 
g.add_legend(); 
g.set(yscale="log") 

如何绘制线性回归线?

请您参考如下方法:

Matplotlib 的 plt.scatter不计算回归线。通过sns.regplot改为 g.map(),它默认计算回归线。

你可以看到一些例子here其中不同的绘图函数与 FacetGrid.map()(代码中的 g.map())一起使用。