Skip to content

Instantly share code, notes, and snippets.

@gwgundersen
Created November 12, 2019 18:41
Show Gist options
  • Save gwgundersen/90dfa64ca29aa8c3833dbc6b03de44be to your computer and use it in GitHub Desktop.
Save gwgundersen/90dfa64ca29aa8c3833dbc6b03de44be to your computer and use it in GitHub Desktop.
Contour plot of 2D gaussian
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import multivariate_normal
N = 200
X = np.linspace(-4, 4, N)
Y = np.linspace(-4, 4, N)
X, Y = np.meshgrid(X, Y)
pos = np.dstack((X, Y))
rv = multivariate_normal([0, 1], [[1, 0.8], [0.8, 1]])
Z = rv.pdf(pos)
plt.contour(X, Y, Z)
plt.show()
@herzphi
Copy link

herzphi commented Feb 1, 2023

This is one solution, but if you want to define the contour levels to be a certain amount of probability you can use my repo: herzphi/2DGaussianContourLevels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment