karthiks
karthiks

Reputation: 7299

What is the seaborn equivalent for matplotlilb histrogram of a column values?

I have code snippet in matplotlilb like below:

df['coln1'].plot(kind='hist') # This works!

I tried to use the seaborn API to plot the same and my Jupyter Notebook hangs inefinitely. I tried the code below that fails:

sns.barplot(x=df.index, y=df['coln1']) # What is the right way in seaborn?

UPDATE: My objective is to see visually the distribution of values for a given column, using seaborn API.

Your help is much appreciated.

Upvotes: 0

Views: 258

Answers (2)

Matt Elgazar
Matt Elgazar

Reputation: 735

import seaborn as sns

sns.distplot(df[column], bins=bins)

Upvotes: 1

TwinPenguins
TwinPenguins

Reputation: 495

The equivalent solution to matplotlilb borrowed from the seaborn official documentation is shown below:

import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")

tips.head(5)
   total_bill   tip     sex smoker  day    time  size
0       16.99  1.01  Female     No  Sun  Dinner     2
1       10.34  1.66    Male     No  Sun  Dinner     3
2       21.01  3.50    Male     No  Sun  Dinner     3
3       23.68  3.31    Male     No  Sun  Dinner     2
4       24.59  3.61  Female     No  Sun  Dinner     4

You can simply do this:

ax = sns.distplot(tips["total_bill"])

Which gives you the distribution of values in the "total_bill" column.

Upvotes: 1

Related Questions