Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: Contour levels must be increasing - Contour plot in Python

I am trying to plot density estimates using a contour plot and getting the following error.

A = np.random.uniform(size=(100, 2))
#mean = np.mean(x)
#cov = np.cov(x)
mean = np.array([0.5, 0.1])
cov = np.array([[0.1, 0.0], [0.0, 1.5,]])

B = multivariate_normal.pdf(A, mean=mean, cov=cov)


# visualize
contours = plt.contour(A, B, linewidths=2)
plt.clabel(contours, inline=True,  fontsize=12)
#plt.plot(x, y)
plt.colorbar();
like image 249
ferrelwill Avatar asked Mar 18 '26 19:03

ferrelwill


1 Answers

For someone in future that has this problem in seaborn, I discovered that my data had some extreme outliers, meaning there was effectively no density to plot as 99% of the samples were around the origin. Using the 'clip' functionality in kdeplot worked to reduce the axis and thus plot the actual levels.

like image 94
lemmykc Avatar answered Mar 21 '26 11:03

lemmykc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!