2 回答

TA貢獻1862條經驗 獲得超6個贊
不確定這是否是您想要的。
hist2d 文檔指定該函數返回一個大小為 4 的元組,其中第一項h是熱圖。
這h將具有與 相同的形狀bins。
您可以捕獲輸出(它仍會繪制),并用于argwhere查找值超過第 90 個百分位數的坐標:
h, xedges, yedges, img = hist = plt.hist2d(X, Y, bins=(160,160), norm=mpl.colors.LogNorm(vmin=1, vmax=20))
print(list(np.argwhere(h > np.percentile(h, 90))))

TA貢獻1875條經驗 獲得超5個贊
你需要Seaborn包。
你提到
我希望能夠獲得此直方圖的結果并過濾掉具有低值的箱子,保留高箱子。
你絕對應該使用其中之一:
seaborn.joinplot(...,kind='hex')
:它顯示落在六邊形箱內的觀測值的計數。該圖最適合相對較大的數據集。seaborn.joinplot(...,kind='kde')
:使用核密度估計來可視化雙變量分布。我推薦它更好。
示例“哪里”
使用級別數n_levels
并shade_lowest=False
忽略低值。
import seaborn as sns
import numpy as np
import matplotlib.pylab as plt
x, y = np.random.randn(2, 300)
plt.figure(figsize=(6,5))
sns.kdeplot(x, y, zorder=0, n_levels=6, shade=True, cbar=True,
shade_lowest=False, cmap='viridis')
添加回答
舉報