简体   繁体   中英

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

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:

在此处输入图片说明

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'}})
plt.show()

Output: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM