user11566345
user11566345

Reputation:

How to set the color of the dots except for the main diagonal in seaborn?

This figure (fig_1) is a pairwise scatter plot on iris dataset. The diagonal plots the marginal histograms of the 4 features.

enter image description here

I am trying to reproduce this figure with Python.

here is the code

>>> import numpy as np, pandas as pd; np.random.seed(0)
>>> import seaborn as sns; sns.set(style="white", color_codes=True)
>>> iris = sns.load_dataset("iris")
>>> g = sns.pairplot(iris, vars = iris.columns[0:4] , diag_kind = 'hist')

the output (fig_2) is

enter image description here

How to set the color of the dots except for the main diagonal, shown as the fig_1?

I've also tried hue option which colors the main diagonal as well, that's why I said "except for the main diagonal".

Upvotes: 0

Views: 616

Answers (2)

Abishek Aditya
Abishek Aditya

Reputation: 812

Try this, sns.pairplot(iris,hue="species",diag_kws=dict(color="b")).

The diag_kws applies the values to only the diagonal plots

Upvotes: 1

Quang Hoang
Quang Hoang

Reputation: 150785

Based on @ImportanceOfBeingErnest comment:

g = sns.PairGrid(iris)
g = g.map_diag(plt.hist)
g = g.map_offdiag(sns.scatterplot, hue=iris['species'])

Output:

enter image description here

Upvotes: 0

Related Questions