Python 2D KDE 强度

问题描述

我目前正在使用 gaussian_kde 对一组坐标点进行 KDE(每个点代表一个案例)。我能够画出很棒的轮廓;但是,当我查看实际的轮廓级别值时,它们似乎非常高(例如,1284 最高应该接近 20 个案例/km^2)。我希望将级别定义为案例/km^2;但是,我似乎无法从 scipy 获得该输出。有谁知道我如何获得这些数据?

参考代码

import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde


# plot out map itself
census_tracts = gpd.read_file('../app/static/census.geojson')
fig,ax = plt.subplots(figsize=(10,10))
census_tracts.plot(ax=ax,facecolor="none",edgecolor='black',zorder=1)

x,y = # geographic coordinates of the cases.
xi,yi = np.mgrid[x.min():x.max():100j,y.min():y.max():100j]

positions = np.vstack([xi.ravel(),yi.ravel()])
values = np.vstack([x,y])

k = gaussian_kde(values,bw_method=0.1)

f = np.reshape(k(positions).T,xi.shape)


linsep = np.linspace(min(k(positions).T),max(k(positions).T),7)
print(linsep)
ax.contourf(xi,yi,f,np.linspace(linsep[1],6),alpha=0.5)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)