简体   繁体   English

如何在python中绘制高斯形状的直方图?

[英]How to plot Gaussian shaped histogram in python?

I have a df named s with just one column: 我有一个名为sdf只有一列:

size
20
28
38
42
42
42
44
124
176
192
194
216
228
316
318
2048
2714
2802
4128
4186
6910
9313
10816
16560
20704
34766
91022

and I am plotting a histogram for the same using 我正在使用相同的直方图

sns.distplot(s['size'], bins = len(s))

and it yields a result as follows: 它产生如下结果: 在此输入图像描述

I would like to know how can I make a few changes: 我想知道如何进行一些更改:

  1. I would like to histogram to have a kind of gaussian look as follows: Example of a Gaussian look (this is just an example to show the kind of histogram I am expecting) 我想直方图有一种高斯外观如下: 高斯外观的例子(这只是一个例子来显示我期待的直方图的类型)
  2. In the graph I plotted, the bins are not continuous, meaning there is a gap between 2 bins. 在我绘制的图表中,箱子不是连续的,意味着在2个箱子之间存在间隙。 I want to have no gaps between 2 bins while I am plotting them. 我想绘制它们时,我想在2个箱子之间没有间隙。

I would like to know how can these 2 tasks be achieved. 我想知道如何实现这两项任务。

Thanks 谢谢

You're going to struggle getting the "Guassian look" you want given that this data is not normally distributed. 鉴于此数据不是正常分布的,您将很难获得您想要的“高斯外观”。

Using the size column as counts is the closest you'd be able to get to the "Guassian look" you linked (if this is at all how your data can be interpreted). 使用size列作为计数是您最接近您链接的“Guassian外观”(如果这完全是您的数据如何解释)。

import matplotlib.pyplot as plt
from io import StringIO
import pandas as pd

plt.style.use('seaborn')

data = pd.read_fwf(StringIO("""
20
28
38
42
42
42
44
124
176
192
194
216
228
316
318
2048
2714
2802
4128
4186
6910
9313
10816
16560
20704
34766
91022
"""), names=['size'], header=None)

plt.bar(range(data['size'].size), data['size'], width=1)
plt.xlabel('bin')
plt.ylabel('size')

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM