Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change line style for different regression lines in seaborn implot?

Tags:

python

seaborn

I want to change the line style in seaborn implot. I know that we can do the following for changing line style for one regression line.

sns.lmplot(x='xx' , data=dataset, y='yy',line_kws={'ls':'--'})

But what about using hue in implot, when we have three regression line for example:

 sns.lmplot(x='xx' , data=dataset, y='yy',hue='class', markers=["o", "x", "D"])

How can we do that? How can we change the line style of each regression line?

like image 367
Enayat Avatar asked Sep 02 '25 10:09

Enayat


1 Answers

Don't think you can :( Here's a workaround that looks similar to lmplot but uses regplot in order to control the individual linestyles:

import seaborn as sns; sns.set(color_codes=True)
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

_, ax = plt.subplots(figsize=(6, 6))
for d, m, ls in zip(tips["day"].unique(), ["o", "x", ".", "D"], ["--", ":", "-.", "-"]):
    sns.regplot(x="total_bill", y="tip", data=tips.loc[tips.day == d], marker=m, line_kws={"ls":ls}, ax=ax, label=d)
plt.legend()

enter image description here

like image 161
cosmic_inquiry Avatar answered Sep 04 '25 22:09

cosmic_inquiry