简体   繁体   English

如何使用 python plot 高斯 pdf 的轮廓?

[英]How can I plot the contours of a Gaussian pdf using python?

I have the old faithfutl data set, and I want to replicate this plot:我有旧的faithfutl 数据集,我想复制这个plot:

在此处输入图像描述

I do not know how to plot it.我不知道怎么plot吧。 I have the mean and the variance.我有均值和方差。 I know how to do it with a multivariate gaussian, but with the univariate one I am having this error: TypeError: Input z must be 2D, not 3D我知道如何使用多元高斯函数,但使用单变量高斯函数时出现此错误:TypeError: Input z must be 2D, not 3D

This is my code:这是我的代码:

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')

Well, I came up with the code:好吧,我想出了代码:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM