Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove transparency from a histogram created using Seaborn in python?

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

like image 699
Turke Avatar asked May 06 '16 18:05

Turke


People also ask

How do you change the transparency of a histogram in Python?

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.

How do you change the transparency in Seaborn plot?

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 .

How do you change the color of a histogram in Seaborn?

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.


1 Answers

sns.distplot(iris.petal_length, axlabel = 'Petal Length', hist_kws=dict(alpha=1))
like image 111
mwaskom Avatar answered Sep 25 '22 01:09

mwaskom