简体   繁体   English

numpy 2d直方图的标准偏差

[英]Standard deviation from numpy 2d histogram

给定一系列 2d 坐标以及每个坐标的加权值,是否有一种方法可以使用 numpy histrogram2d 方法确定每个 bin 中的标准偏差?

Not Sure what are you asking, could you post your code?不知道你在问什么,你能发布你的代码吗?

I generally plot std on hist drawing verticals lines as follows:我通常在 hist 绘制垂直线时绘制 std 如下:

plt.axvline(x=np.mean(data)-np.std(data), ls = "--", color='#2ca02c', alpha=0.7)
plt.axvline(x=np.mean(data)+np.std(data), ls = "--", color='#2ca02c', alpha=0.7)

Where "data" is a dictionary with all the values其中“数据”是包含所有值的字典图像

It's not directly possible with numpy's histrogram2d but with scipy.stats.binned_statistic_2d it can be done quite easily.使用 numpy 的histrogram2d不能直接实现,但使用scipy.stats.binned_statistic_2d可以很容易地完成。

from scipy import stats

x = np.random.rand(10000)
y = np.random.rand(10000)
z = np.random.rand(10000)
binx = np.linspace(0,x.max(), 100)
biny = np.linspace(0,y.max(), 100)
hist = stats.binned_statistic_2d(x, y, z, statistic='std', bins=[binx, biny])
plot_x, plot_y = np.meshgrid(binx, biny)

fig, ax = plt.subplots(figsize=(5,5))
pc = ax.pcolormesh(plot_x, plot_y, hist[0].T, cmap="inferno")
ax.set_aspect('equal')
cbar=fig.colorbar(pc,shrink=0.725)
fig.tight_layout()

在此处输入图片说明

The statistic option can also take different things like mean , median or a user-defined function, see the documentation for more details. statistic选项还可以采用不同的东西,例如meanmedian或用户定义的函数,有关更多详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM