abu
abu

Reputation: 777

Change the regression line colour of Seaborn's pairplot

I would like to change the color of the regression lines to a different one. I found a similar question regarding a joint plot, however, as far as I know it is not analogical to the pairplot. I am attaching an example:

import seaborn as sns; 
sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
g = sns.pairplot(iris, kind="reg")

Upvotes: 13

Views: 13948

Answers (2)

Ledian K.
Ledian K.

Reputation: 585

The accepted solution is already very nice. Just for sake of completeness to the answer I would suggest to create a "corner" plot by not showing the axes to the upper (off-diagonal) triangle of the grid. You can do that by adding the corner=True parameter.

import seaborn as sns
sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
g = sns.pairplot(iris, kind="reg", corner=True, plot_kws={'line_kws':{'color':'red'}})

# A different color for each group
# g = sns.pairplot(iris, kind="reg", hue="species", corner=True, plot_kws={'line_kws':{'color':'red'}}, diag_kind="hist", palette="husl")

plt.show()

Output: enter image description here

Output with different colours: enter image description here

Upvotes: 5

harpan
harpan

Reputation: 8631

You need to pass plot_kws as a dict. You can change the regression line with line_kws. Refer to docs for more information.

import seaborn as sns
sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
g = sns.pairplot(iris, kind="reg", plot_kws={'line_kws':{'color':'red'}})
plt.show()

Output:

enter image description here

Upvotes: 26

Related Questions