簡體   English   中英

如何在 python / plotly 中制作二維向量分布的 3D 直方圖

[英]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 可視化:

雙變量樣本的 KDE 估計器

但我想要一個 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM