matplotlib:从数据中绘制直方图

时间:2013-11-13 13:22:26

标签: python file matplotlib histogram

我有想要绘制为直方图的数据(光谱)。 我导入数据,spectrum.shape显示我(1024,)作为格式, 但是plt.hist没有正确绘制数据。 如果我使用plt.bar(...)它工作正常,但出于审美原因(我想使用“stepfilled”直方图设计),我必须使用提供此选项的plt.hist。 我真的不知道该怎么办。 这是我的代码:

import matplotlib.pyplot as plt
import numpy as np

spectrum = np.loadtxt('3000.mp',  skiprows=53)

y1=spectrum[:]
num_bins = 1024
diagram = plt.hist(y1, num_bins, alpha=0.5)
plt.xlabel("TOF / $\mu$s")
plt.ylabel("# ions")
plt.show()

我希望得到你的帮助。

1 个答案:

答案 0 :(得分:0)

我也对这个答案感兴趣。你会分享你是如何通过酒吧获得逐步填充的设计的吗?

我自己正在寻找这样的事情:

enter image description here

(此图片来自http://astroplotlib.stsci.edu/page_histograms.htm

但我无法通过光谱作为输入轻松生成它。

相关问题