Issue
I'm trying to use a contour plot to visualize a multivariate normal distribution.
import numpy as np
from scipy.stats import multivariate_normal
mean = (0, 0)
cov = [[1, 0.75],
[0.75, 1]]
data = np.random.multivariate_normal(mean, cov,size=1000)
var = multivariate_normal(mean=mean, cov=cov)
z = var.pdf(data)
plt.contour(data,z)
>>>
ValueError: Contour levels must be increasing
My goal is simply a contour plot of the multivariate distribution, much like a 2D histogram. However, I seem to be misunderstanding the function's intent.
Is there a better way to accomplish this effect?
Solution
You can use seaborn kde plot:
import seaborn as sns
sns.kdeplot(data, bw=.15)
plt.show()
as described here https://seaborn.pydata.org/generated/seaborn.kdeplot.html for easy plotting.
I know it is not the exact answer to your problem but it might be sufficient answer for you if you are willing to install the seaborn library.
Answered By - Vladimír Kunc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.