Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

As of Matplotlib 3.1, mlab.bivariate_normal is removed from matplotlib's library. I was wondering if there is a built-in class that does the same job elsewhere (or in matplotlib)? I searched for a bit but can't find it readily.

I realize that one can just copy the function here and use it but I was wondering if there is a built-in function that one can call.

As suggested by @tmdavison, scipy.stats.multivariate_normal() can be used to replace matplotlib.mlab.bivariate_normal() .

The call:

Z = matplotlib.mlab.bivariate_normal(X, Y, sig_x, sig_y, mu_x, mu_y, sig_xy)

becomes:

rv = scipy.stats.multivariate_normal([mu_x, mu_y], [[sig_x, sig_xy], [sig_xy, sig_y]])
Z = rv.pdf(np.dstack((X, Y)))

The matplotlib.mlab.bivariate_normal() function had default values for all arguments except X and Y so you may have to add some extra values. The sig_x and sig_y values defaulted to 1.0 and all other arguments defaulted to 0.0. So if you are replacing the call bivariate_normal(X, Y) it would become multivariate_normal([0, 0], [[1, 0], [0, 1]]).pdf(np.dstack((X, Y))).

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.