Reputation: 777
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
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 with different colours:
Upvotes: 5
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:
Upvotes: 26