简体   繁体   中英

How to plot Gaussian shaped histogram in python?

I have a df named s with just one column:

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. I want to have no gaps between 2 bins while I am plotting them.

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).

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')

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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