Contour Plot
Double Slit Diffraction Pattern
Contour plot showing two-source wave interference pattern.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
x = np.linspace(-10, 10, 200)
y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)
r1 = np.sqrt((X + 3)**2 + Y**2)
r2 = np.sqrt((X - 3)**2 + Y**2)
Z = np.sin(r1 * 2) + np.sin(r2 * 2)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
colors = ['#1e3a8a', '#60a5fa', '#ffffff', '#fca5a5', '#9C2007']
cmap = LinearSegmentedColormap.from_list('wave', colors, N=256)
cs = ax.contourf(X, Y, Z, levels=30, cmap=cmap)
ax.contour(X, Y, Z, levels=15, colors='#374151', linewidths=0.3, alpha=0.4)
cbar = plt.colorbar(cs, ax=ax, pad=0.02)
cbar.set_label('Amplitude', color='#374151', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='#374151')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#374151')
ax.plot(-3, 0, 'o', color='#F5276C', markersize=8)
ax.plot(3, 0, 'o', color='#F5276C', markersize=8)
ax.set_xlabel('X', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Y', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Double Slit Diffraction Pattern', 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
☕