I have three datasets (df1, df2, df3, randomly generated here as an example) that I want to plot the joint kernel densities together on a black background. I don't like how the overlapping parts of the joint kdes look because when the white parts (lowest densities) overlap against the black background it really sticks out. In contrast this looks fine against a white background (will include at the bottom for comparison), but I need it to be a black background.
An idea for how to make this better could be:
- Reverse the color bar so that the lowest densities are the dark colors and the higher densities are the bright colors.
Does anyone know how to do this or how to make it better?
I didn't know where to start looking but I found this closed issue on seaborn's GitHub that talks a little bit about shading.
import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
# Uncomment for black background figure
plt.rcParams.update({
"grid.color": "white",
'hatch.color': 'k',
"lines.color": "white",
"patch.edgecolor": "white",
'patch.facecolor': ([0, 1, 1]),
'grid.alpha': 0.4,
"text.color": "lightgray",
"axes.facecolor": "black",
"axes.edgecolor": "lightgray",
"axes.labelcolor": "white",
"xtick.color": "white",
"ytick.color": "white",
"grid.color": "lightgray",
"figure.facecolor": "black",
"figure.edgecolor": "black",
"savefig.facecolor": "black",
"savefig.edgecolor": "black"})
df1 = pd.DataFrame(np.random.randint(0,60,size=(1500, 4)), columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randint(20,80,size=(1500, 4)), columns=list('ABCD'))
df3 = pd.DataFrame(np.random.randint(40,100,size=(1500, 4)), columns=list('ABCD'))
f, axs = plt.subplots()
# Draw density plots
axs = sns.kdeplot(df1.A, df1.B, alpha=0.5,
cmap="Reds", shade=True, shade_lowest=False, cbar=True)
axs = sns.kdeplot(df2.A, df2.B, alpha=0.5,
cmap="Oranges", shade=True, shade_lowest=False, cbar=True)
axs = sns.kdeplot(df3.A, df3.B, alpha=0.5,
cmap="Blues", shade=True, shade_lowest=False, cbar=True)