Lord Zsolt
Lord Zsolt

Reputation: 6557

Seaborn distplot only whole numbers

How can I make a distplot with seaborn to only have whole numbers?

My data is an array of numbers between 0 and ~18. I would like to plot the distribution of the numbers.

Impressions
0      210
1     1084
2     2559
3     4378
4     5500
5     5436
6     4525
7     3329
8     2078
9     1166
10     586
11     244
12     105
13      51
14      18
15       5
16       3
dtype: int64

Code I'm using:

sns.distplot(Impressions,
              # bins=np.arange(Impressions.min(), Impressions.max() + 1),
              # kde=False,
             axlabel=False,
             hist_kws={'edgecolor':'black', 'rwidth': 1})
plt.xticks = range(current.Impressions.min(), current.Impressions.max() + 1, 1)

Plot looks like this:

enter image description here

What I'm expecting:


Am I using the correct tool for the job or distplot shouldn't be used for whole numbers?

Upvotes: 1

Views: 4924

Answers (1)

Rudra Mohan
Rudra Mohan

Reputation: 790

For your problem can be solved bellow code,

import seaborn as sns # for data visualization
import numpy as np # for numeric computing
import matplotlib.pyplot as plt # for data visualization

arr = np.array([1,2,3,4,5,6,7,8,9])

sns.distplot(arr, bins = arr, kde = False)
plt.xticks(arr)
plt.show()

enter image description here

In this way, you can plot histogram using seaborn sns.distplot() function.

Note: Whatever data you will pass to bins and plt.xticks(). It should be an ascending order.

Upvotes: 1

Related Questions