[英]Seaborn distplot only whole numbers
How can I make a distplot with seaborn to only have whole numbers? 我怎样才能让seaborn变成只有整数的图?
My data is an array of numbers between 0 and ~18. 我的数据是0到〜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: 情节看起来像这样:
What I'm expecting: 我期望的是:
(x, x + 1)
, hence why the downward spike (This isn't required, I can turn off kde) (x, x + 1)
之间有0,因此为什么会有向下的尖峰(这不是必需的,我可以关闭kde) Am I using the correct tool for the job or distplot shouldn't be used for whole numbers? 我是否应为作业或分配图使用正确的工具?
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. 这样,您可以使用seaborn
sns.distplot()
函数绘制直方图。
Note: Whatever data you will pass to bins and plt.xticks(). 注意:无论传递到bins和plt.xticks()的任何数据。 It should be an ascending order.
它应该是一个升序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.