我使用Python处理一个非常大的数据集,因此我尝试使用直方图而不是数组(数组太大,无法保存/加载/映射)。我在一堆文件上爬行,从中提取信息,然后我想获取信息,然后重新制作直方图。我可以使用1D柱状图进行此操作,如下所示:
counter, bins = np.histogram(nSigmaProtonHisto, bins=1000, range=(-10000, 10000))
nSigmaProtonPico[0] += counter
nSigmaProtonPico[1] = bins[:-1]
nSigmaProtonPico是一个2D数组,用于存储箱边和直方图值的最终计数。nSigmaProtonHisto是一个用于特定事件的一维数组,我循环了数百万个事件。一旦脚本完成,它将爬过所有事件,我将有一个带有直方图值和位置的2D数组。我可以简单地画出它,如下所示:
plt.plot(nSigmaProtonPico[1], nSigmaProtonPico[0])
当我尝试对2D直方图执行此操作时,它会崩溃。我错过了一些东西。以下是我所拥有的:
counter, bins1, bins2 = np.histogram2d(dEdX, pG, bins=1000, range=((0, 20), (-5, 5)))
dEdXpQPRIME[0] += counter[0]
dEdXpQPRIME[1] += counter[1]
dEdXpQPRIME[2] = bins1[:-1]
dEdXpQPRIME[3] = bins2[:-1]
这让我得到了一些东西,但我不知道如何绘制它,以便从所有数据中重现直方图。我认为它会像x,y,z坐标一样简单,但是有4个坐标,而不是3个坐标
我错过了什么
counter
是一个二维数组。如果每次调用histogram2d
时都有相同的bin,那么将得到相同大小的数组。因此,您可以简单地添加所有counter
数组。 考虑:H1
和H2
都是形状(99,99)
(每个维度有100条边)相关问题 更多 >
编程相关推荐