Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linear regression line on facet grid with logarithmic Y axis

I have code working exactly as I want: it plots two colored datasets, TypeA and TypeB, on three plots separated by the value Divison with a logarithmic axis for Y only.

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

Facet Plot

How can I get a linear regression line to plot?

like image 204
pls256 Avatar asked Dec 06 '25 05:12

pls256


1 Answers

Matplotlib's plt.scatter does not calculate a regression line. Pass sns.regplot to g.map() instead, which calculates a regression line by default.

You can see some examples here where different plotting functions are used with FacetGrid.map() (which is g.map() in your code).

like image 108
jonchar Avatar answered Dec 07 '25 18:12

jonchar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!