Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change colour of histograms in seaborn pairplot (when using jupyter themes)

I'm not sure if it's just the theme and darktheme that I'm using but I can't seem to change the colours of the histogram on my pairplot.

Is there a way to change them as they are very dark looking or is this just because of the theme?

g = sns.pairplot(df)
g.map_upper(sns.scatterplot,color='red')
g.map_lower(sns.scatterplot, color='green')
g.map_diag(plt.hist, color='blue')

pairplot

like image 933
Cormbot Avatar asked Oct 17 '25 19:10

Cormbot


1 Answers

Note that sns.pairplot creates a PairGrid and already draws the scatter dots and histogram. If you then draw your own histogram over it, thes probably don't coincide. Therefore, it can help to replace sns.pairplot with sns.PairGrid giving empty subplots.

The following code has been tested with Seaborn 0.11.1 and matplotlib 3.4.1.

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_theme('notebook', style='dark')
plt.style.use("dark_background")
df = sns.load_dataset('iris')
g = sns.PairGrid(df)
g.map_upper(sns.scatterplot, color='crimson')
g.map_lower(sns.scatterplot, color='limegreen')
g.map_diag(plt.hist, color='skyblue')
plt.show()

pairgrid change colors

like image 179
JohanC Avatar answered Oct 20 '25 11:10

JohanC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!