1

我有要绘制为直方图的数据(光谱)。我导入数据并将spectrum.shape我 (1024,) 显示为格式,但是plt.hist没有正确绘制数据。如果我使用plt.bar(...)它就可以了,但出于审美原因(我想使用“阶梯式”直方图设计),我必须使用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()

我希望能得到你的帮助。

4

1 回答 1

0

我也对这个答案感兴趣。你能分享一下你是如何得到带条的阶梯式设计的吗?

我自己我正在寻找这样的东西:

在此处输入图像描述

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

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

于 2013-11-21T00:45:07.323 回答