Contour Plot

Gaussian Probability Density

Bivariate normal distribution visualized as contour plot showing probability density levels.

Output
Gaussian Probability Density
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Create bivariate Gaussian
x = np.linspace(-4, 4, 200)
y = np.linspace(-4, 4, 200)
X, Y = np.meshgrid(x, y)

# Bivariate normal with correlation
mu_x, mu_y = 0, 0
sigma_x, sigma_y = 1, 1.5
rho = 0.6

z1 = (X - mu_x) / sigma_x
z2 = (Y - mu_y) / sigma_y
Z = np.exp(-1/(2*(1-rho**2)) * (z1**2 - 2*rho*z1*z2 + z2**2))
Z = Z / (2 * np.pi * sigma_x * sigma_y * np.sqrt(1 - rho**2))

# Modern dark theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Custom colormap - vibrant purple-pink gradient
colors = ['#0a0a0f', '#1a0a2e', '#2d1a4a', '#4a2a6a', '#6a3a8a', 
          '#8a4aaa', '#aa5aca', '#ca6aea', '#ea7aff', '#ff8aff']
cmap = LinearSegmentedColormap.from_list('neon_purple', colors, N=256)

# Filled contour with glow effect
cf = ax.contourf(X, Y, Z, levels=25, cmap=cmap)

# Subtle contour lines
cs = ax.contour(X, Y, Z, levels=12, colors='#ff8aff', linewidths=0.4, alpha=0.3)

# Mark center with glow
ax.scatter([mu_x], [mu_y], color='#ff8aff', s=150, marker='+', linewidths=3, zorder=5)
ax.scatter([mu_x], [mu_y], color='#ff8aff', s=300, marker='+', linewidths=1, alpha=0.3, zorder=4)

# Styled colorbar
cbar = plt.colorbar(cf, ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#0a0a0f')
cbar.set_label('Probability Density', fontsize=11, color='#e0e0ff', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#e0e0ff')
cbar.outline.set_edgecolor('#3a3a5a')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#e0e0ff', fontsize=9)

# Labels with modern styling
ax.set_xlabel('X', fontsize=13, color='#e0e0ff', fontweight='600', labelpad=10)
ax.set_ylabel('Y', fontsize=13, color='#e0e0ff', fontweight='600', labelpad=10)
ax.set_title('Bivariate Gaussian Distribution', fontsize=16, color='white', 
             fontweight='bold', pad=20)

# Style axes
ax.tick_params(colors='#a0a0d0', labelsize=10, length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

# Add subtle grid
ax.grid(True, alpha=0.1, color='#ffffff', linestyle='-', linewidth=0.5)

ax.set_aspect('equal')
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support