Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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")
like image 869
abu Avatar asked Jun 06 '18 14:06

abu


People also ask

How do you change the color of the regression line in Seaborn?

To change the line color in seaborn linear regression jointplot, we can use joint_kws in jointplot() method.

What does a Pairplot show?

A pairplot plot a pairwise relationships in a dataset. The pairplot function creates a grid of Axes such that each variable in data will by shared in the y-axis across a single row and in the x-axis across a single column.

How do you change the color of a Boxplot in Seaborn?

This can be done by adding a palette argument inside the boxplot() function and giving it any predefined seaborn color palette value like “Set1”, “Set2”, “Paired”, “Set3” etc.


1 Answers

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

like image 161
harvpan Avatar answered Oct 06 '22 01:10

harvpan