首页 > 解决方案 > 使用 Python 的配置文件直方图(错误:“FutureWarning:...”

问题描述

对此已经提出了类似的问题:Plotting profile histograms in python。但无论如何,由于某种原因,它对我不起作用。

让我们看看我的代码

 from pylab import *
 import numpy as np
 import matplotlib.pyplot as plt
 import seaborn as sns
 import scipy


 file = open('cesium.txt','r')
 count = 0
 energy_channel = []
 intensity_counts = []
 for line in file.readlines():
     count += 1
     if count >= 10:
         row = line.split()
         int_1 = int(row[0])
         int_2 = int(row[-1])
         energy_channel.append(int_1)
         intensity_counts.append(int_2)
     if count == 2700: break


 plt.plot(energy_channel, intensity_counts, 'k.')
 plt.xlabel('Energy (keV)')
 plt.ylabel('Counts')
 plt.xticks([0, 400, 800, 1200, 1600, 2000, 2400],
            [0, 110, 220, 330, 440, 550, 662])
 plt.show()
 plt.clf()

这将为放射性同位素 Cs-137 绘制所谓的伽马谱(对于感兴趣的人)。现在,我想从这个光谱中制作一个轮廓直方图。由于我将所有点分别存储在两个(x-和y-)向量energy_channel和intensity_counts中,我认为这样的事情可能会起作用:

scipy.stats.binned_statistic(energy_channel,intensity_counts)

但这只是给了我一条错误消息:

 FutureWarning:
 Using a non-tuple sequence for multidimensional indexing is deprecated;
 use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be
 interpreted as an array index, `arr[np.array(seq)]`, which will result
 either in an error or a different result.

我希望我在这里的问题很清楚。我想在我放置链接的线程中制作一个配置文件直方图,但它似乎不像我想的那样工作,我无法弄清楚。

编辑:我尝试使用函数 zip() 将列表制作成元组列表,然后将其提供给 binned_statistics() 函数,但出现相同的错误消息。我也尝试将列表制作成序列,但它似乎也不起作用。

标签: pythonnumpymatplotlibscipyhistogram

解决方案


推荐阅读