Change color of seaborn distribution line
12,424
For changing the color of the fitted curve, you need to set fit_kws
argument. But fit_kws
does not support shading. You can still shade the area below the fitted curve by a few extra lines of code as shown below but that I think is an answer to another question that you have posted.
import numpy as np
import seaborn as sns
import scipy.stats as stats
import matplotlib.pyplot as plt
sns.set()
np.random.seed(0)
x = np.random.randn(100)
y = np.random.normal(loc=6.0, scale=1, size=(50,))
ax = sns.distplot(x, fit_kws={"color":"red"}, kde=False,
fit=stats.gamma, hist=None, label="label 1");
ax = sns.distplot(y, fit_kws={"color":"blue"}, kde=False,
fit=stats.gamma, hist=None, label="label 2");
plt.show(block=False)
The result of the code is show below:
Comments
-
JAG2024 almost 2 years
I want to specify the color of a line of
fit
within the seaborn package for an array ofx
andy
data. Instead all I can figure out is how to change the color and shading for the kernel density function. How can I change the color for a gaussian fit? I.e. the lines below should be red and blue. It would also be great to shade in the function like the"shade":True
argument.import seaborn as sns sns.distplot(x,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="red", label="label 1"); sns.distplot(y,kde_kws={"shade":True}, kde=False, fit=stats.gamma, hist=None, color="blue", label="label 2");
-
JAG2024 over 6 yearsThanks for this. I had a tough time finding the arguments for
fit_kws
. Bummer that's it's complicated to shade. -
Admin over 6 yearsYes. It is a bit complicated to shade.