0

I have the old faithfutl data set, and I want to replicate this plot:

enter image description here

I do not know how to plot it. 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

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')
  • you need to plot `z` against `w_0` and `w_t`, not `t, h` – Paul H Feb 15 '21 at 20:01
  • Also see [this tutorial example](https://matplotlib.org/stable/gallery/statistics/confidence_ellipse.html) and [Creating Confidence Ellipses in a scatterplot](https://stackoverflow.com/questions/20126061/creating-a-confidence-ellipses-in-a-sccatterplot-using-matplotlib) – JohanC Feb 15 '21 at 21:04

1 Answers1

0

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