I'm creating histograms using seaborn in python and want to customize the colors. The default settings create transparent histograms, and I would like mine to be solid. How do I remove the transparency?
I've tried creating a color palette and setting desaturation to 0, but this hasn't changed the saturation of the resulting histogram.
Example:
# In[1]:
import seaborn as sns
import matplotlib.pyplot as plt
get_ipython().magic('matplotlib inline')
# In[2]:
iris = sns.load_dataset("iris")
# In[3]:
myColors = ['#115e67','#f4633a','#ffd757','#4da2e8','#cfe5e5']
sns.palplot(sns.color_palette(myColors))
# In[4]:
sns.set_palette(palette=myColors,desat=0)
# In[5]:
sns.set(style="white")
# In[6]:
sns.despine()
# In[7]:
plt.title('Distribution of Petal Length')
sns.distplot(iris.petal_length, axlabel = 'Petal Length')
Distribution of petal length
Changing the transparency You can change how transparent the histogram is by adding the argument 'alpha' with values between 0 to 1. 1 is the default value.
Setting transparent background To set a transparent background you could use the RGBA tuple (0,0,0,0) , where the last 0 represents an opacity of 0 .
By dfault, Seaborn's distplot() makes the histogram filling the bars in blue. We can manually change the histogram color using the color argument inside distplot() function. In this example, we have used the argument color=”purple” to make purple histogram as shown below.
sns.distplot(iris.petal_length, axlabel = 'Petal Length', hist_kws=dict(alpha=1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With