Created
November 12, 2019 18:41
-
-
Save gwgundersen/90dfa64ca29aa8c3833dbc6b03de44be to your computer and use it in GitHub Desktop.
Contour plot of 2D gaussian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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