Contour Plot
Airfoil Pressure Field
Aerodynamic pressure distribution around an airfoil showing flow patterns.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
# Create grid around airfoil
x = np.linspace(-2, 3, 300)
y = np.linspace(-1.5, 1.5, 200)
X, Y = np.meshgrid(x, y)
# Simplified potential flow
R, U = 0.5, 1.0
alpha = np.radians(5)
r = np.sqrt(X**2 + Y**2)
phi = U * (X * np.cos(alpha) + Y * np.sin(alpha))
phi += -U * R**2 * (X * np.cos(alpha) + Y * np.sin(alpha)) / (X**2 + Y**2 + 0.1)
v_sq = np.gradient(phi, x, axis=1)**2 + np.gradient(phi, y, axis=0)**2
Cp = 1 - v_sq / U**2
Cp = np.clip(Cp, -3, 1.5)
# Mask airfoil
mask = (X > -0.5) & (X < 1) & (np.abs(Y) < 0.15 * (1 - ((X - 0.25)/0.75)**2 + 0.01))
Cp[mask] = np.nan
# Aerospace dark theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(12, 6))
fig.patch.set_facecolor('#08080f')
ax.set_facecolor('#08080f')
# Custom colormap - aerospace
colors = ['#0000aa', '#0033cc', '#0066ee', '#3399ff', '#66ccff',
'#ffffff', '#ffcc66', '#ff9933', '#ff6600', '#cc3300']
cmap = LinearSegmentedColormap.from_list('aero', colors, N=256)
# Filled contour
levels = np.linspace(-2, 1, 30)
cf = ax.contourf(X, Y, Cp, levels=levels, cmap=cmap, extend='both')
# Contour lines
cs = ax.contour(X, Y, Cp, levels=12, colors='white', linewidths=0.3, alpha=0.3)
# Airfoil shape
airfoil_x = np.linspace(-0.5, 1, 100)
airfoil_upper = 0.15 * (1 - ((airfoil_x - 0.25)/0.75)**2)
airfoil_lower = -0.12 * (1 - ((airfoil_x - 0.25)/0.75)**2)
ax.fill_between(airfoil_x, airfoil_lower, airfoil_upper, color='#1a1a2a',
edgecolor='#66aaff', linewidth=2.5)
# Styled colorbar
cbar = plt.colorbar(cf, ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#08080f')
cbar.set_label('Pressure Coefficient (Cp)', fontsize=11, color='#c0d0ff', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#c0d0ff')
cbar.outline.set_edgecolor('#2a2a4a')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#c0d0ff', fontsize=9)
# Labels
ax.set_xlabel('x/c', fontsize=13, color='#c0d0ff', fontweight='600', labelpad=10)
ax.set_ylabel('y/c', fontsize=13, color='#c0d0ff', fontweight='600', labelpad=10)
ax.set_title('Airfoil Pressure Distribution', fontsize=16, color='white',
fontweight='bold', pad=20)
# Style axes
ax.tick_params(colors='#90a0c0', labelsize=10, length=0)
for spine in ax.spines.values():
spine.set_visible(False)
ax.set_aspect('equal')
ax.set_xlim(-1.5, 2.5)
ax.set_ylim(-1, 1)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Contour Plot examples
☕