[英]How can I plot the contours of a Gaussian pdf using python?
我有舊的faithfutl 數據集,我想復制這個plot:
我不知道怎么plot吧。 我有均值和方差。 我知道如何使用多元高斯函數,但使用單變量高斯函數時出現此錯誤:TypeError: Input z must be 2D, not 3D
這是我的代碼:
t = np.linspace(1.5, 6, 100)
h = np.linspace(1.2, 6, 100)
w_0, w_1 = np.meshgrid(t, h)
z = stats.norm(u_ml,sig_ml).pdf(np.dstack((w_0,w_1)))
plt.contourf(t, h,z, cmap='plasma')
好吧,我想出了代碼:
t = np.linspace(1, 6, 100)
h = np.linspace(30, 100, 100)
w_0, w_1 = np.meshgrid(t, h)
z = stats.multivariate_normal(biv_mean,biv_cov).pdf(np.dstack((w_0, w_1)))
plt.figure(figsize=(10,5))
plt.plot(eruptions,waiting,'go')
plt.title("Duration of the eruption in minutes vs the duration in minutes until the next eruption.")
plt.ylabel("waiting")
plt.xlabel("eruption duration")
plt.contour(t, h, z)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.