I am trying to recreate this image (somewhat):
I am currently using contourf in Python, however, I am having difficulties plotting both dsitributions in the same image without one of them being more “dominant”:
I am currently doing the following:
import matplotlib.pyplot as plt
from scipy.stats import multivariate_normal
# Define the mean and covariance for two different multivariate normal distributions
mean1 = [0, 0]
cov1 = [[1, 0.5], [0.5, 1]]
mean2 = [3, 3]
cov2 = [[1, -0.5], [-0.5, 1]]
# Create a grid of (x, y) points
x = np.linspace(-5, 8, 500)
y = np.linspace(-5, 8, 500)
X, Y = np.meshgrid(x, y)
pos = np.dstack((X, Y))
# Compute the density of the multivariate normal distributions
rv1 = multivariate_normal(mean1, cov1)
rv2 = multivariate_normal(mean2, cov2)
Z1 = rv1.pdf(pos)
Z2 = rv2.pdf(pos)
# Create the plot
plt.figure(figsize=(10, 6))
plt.contourf(X, Y, Z1, levels=1000, cmap='Blues', alpha=.5)
plt.contourf(X, Y, Z2, levels=1000, cmap='Blues', alpha=.5)
# plt.gca().set_facecolor('white') # Set background to white
# plt.title('2D Density Plot of Two Different Multivariate Normal Distributions')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()