[英]How to make a 3D histogram of a 2D vector distribution in python / plotly
所以,基本上我在 python 中有一个二维向量列表,我想通过 plotly 对该向量的分布进行 3d 可视化,如曲面曲线。 我将留下我的向量的前 4 个组件的样本
[[0.35431211986827776, 0.21438054570807566], [0.35431211986827776, 0.21438054570807566], [0.35431211986827776, 0.21438054570807566], [0.35431211986827776, 0.21438054570807566],
所以我使用了seaborn.kdeplot()
进行可视化,只给出了 KDE 的 2D 可视化:
但我想要一个 3D 结果,就像在这个二元正态分布 plot 中一样,其中 de X 和 Y 轴是二维矩阵,z 轴是 pdf:
我想我只需要为列表中的每个向量找到一个好的 pdf 估计值。 有没有办法将 KDE 拟合到我的数据中,以便获得每个向量的这种近似分布,然后是 plot 表面?
非常感谢
这是一种方法:
x = np.random.normal(5, 10, 100000)
y = np.random.normal(10, 3, 100000)
h = np.histogram2d(x, y, bins=50)
def bin_centers(bins):
centers = (bins + (bins[1]-bins[0])/2) [:-1]
return centers
x_bins_centers = bin_centers(h[1])
y_bins_centers = bin_centers(h[2])
df = pd.DataFrame(h[0], index=x_bins_centers, columns=y_bins_centers)
fig = go.Figure(data=[go.Surface(z=df)])
fig.show()
结果是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.