python - 使用 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() 函数,但出现相同的错误消息。我也尝试将列表制作成序列,但它似乎也不起作用。
解决方案
推荐阅读
- javascript - 我有四个菜单按钮,但是通过jQuery只有一个弹出窗口,我可以概括还是需要四个不同的窗口?
- c++ - 使用 SET(C++) 检查两个给定字符串是否为字谜时出现运行时错误
- python - 好奇口译员在这里做什么
- javascript - JavaScript中的日期方法在存储在另一个变量中时表现不同
- java - 高内聚和松耦合的优化
- go - 在不同类型的结构之间复制公共字段
- c# - 不明白如何定位 UI rectTransform
- javascript - 如何修复或摆脱 ASP.NET Razor 应用程序中的 ESLint 定义要求?
- matlab - Matlab中整个矩阵的Z分数
- python - Python 将 tweepy 推文和用户 ID 转换为科学记数法