【问题标题】:How can I plot the contours of a Gaussian pdf using python?如何使用 python 绘制高斯 pdf 的轮廓?
【发布时间】:2021-05-18 17:10:48
【问题描述】:

我有旧的 Faithfutl 数据集,我想复制这个情节:

我不知道如何绘制它。我有均值和方差。我知道如何使用多元高斯函数,但使用单变量高斯函数时出现此错误: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')

【问题讨论】:

标签: python python-3.x matplotlib statistics probability


【解决方案1】:

好吧,我想出了代码:

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

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 2020-08-16
    • 2018-07-09
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多