如何使用python绘制直方图

时间:2017-04-22 12:28:30

标签: python histogram

我是Python新手,我希望在文本文件中有一个值的直方图。但我得到一个只有我的文本文件的第一个值的直方图(见图) enter image description here

我的文件如下:

2.52549
2.52821
4.69718
4.81173
4.85834
4.87637
3.03348
3.21677
3.28373
3.11296
3.11947
3.14685
3.19684
3.19533
3.20035
3.36578
3.3899
3.40696
3.47841
3.54231
3.54343
5.20521
5.23496
5.23317
6.1397
6.18261
6.18782
6.1184
6.20701
6.25631

我的代码如下

import matplotlib.pyplot as plt
import numpy as np
import plotly.plotly as py
from pylab import show,hist

gaussian_numbers = np.random.randn(1000)
data_Distanz = np.genfromtxt('data_Distance.txt')
x = data_Distanz[0]
plt.hist(x)
plt.title("Histogram")
plt.xlabel("Distance in m")
plt.ylabel("Amplitude")
plt.savefig('Histogram.png', bbox_inches='tight')
show()

感谢您的帮助。提前谢谢!

0 个答案:

没有答案