Contour Plot
Gravitational Potential Well
Contour plot showing gravitational potential around two massive bodies.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
x = np.linspace(-5, 5, 200)
y = np.linspace(-5, 5, 200)
X, Y = np.meshgrid(x, y)
# Two-body gravitational potential
m1, m2 = 1, 0.5
x1, y1 = -1.5, 0
x2, y2 = 1.5, 0
r1 = np.sqrt((X - x1)**2 + (Y - y1)**2) + 0.1
r2 = np.sqrt((X - x2)**2 + (Y - y2)**2) + 0.1
Z = -m1/r1 - m2/r2
Z = np.clip(Z, -15, 0)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
# Purple gradient
colors = ['#f5f3ff', '#c4b5fd', '#8b5cf6', '#5314E6', '#3b0764']
cmap = LinearSegmentedColormap.from_list('gravity', colors, N=256)
cs = ax.contourf(X, Y, Z, levels=30, cmap=cmap)
ax.contour(X, Y, Z, levels=15, colors='#4c1d95', linewidths=0.4, alpha=0.5)
cbar = plt.colorbar(cs, ax=ax, pad=0.02)
cbar.set_label('Potential (J/kg)', color='#374151', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='#374151')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#374151')
ax.plot(x1, y1, 'o', color='#F5276C', markersize=12)
ax.plot(x2, y2, 'o', color='#F5276C', markersize=8)
ax.set_xlabel('X (AU)', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Y (AU)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Gravitational Potential Well', fontsize=14, color='#1f2937', fontweight='bold', pad=15)
ax.tick_params(colors='#6b7280', labelsize=9)
for spine in ax.spines.values():
spine.set_color('#d1d5db')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Contour Plot examples
☕