Contour Plot
Topographic Terrain Map
Mountain terrain elevation visualization with contour lines mimicking topographic maps.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
# Generate terrain-like surface
np.random.seed(42)
x = np.linspace(0, 10, 200)
y = np.linspace(0, 10, 200)
X, Y = np.meshgrid(x, y)
# Multiple peaks and valleys
Z = (3 * np.exp(-((X-3)**2 + (Y-3)**2)/2) +
4 * np.exp(-((X-7)**2 + (Y-6)**2)/3) +
2 * np.exp(-((X-5)**2 + (Y-8)**2)/1.5) +
2.5 * np.exp(-((X-2)**2 + (Y-7)**2)/2) +
1.5 * np.exp(-((X-8)**2 + (Y-2)**2)/1))
Z += 0.3 * np.sin(X*3) * np.cos(Y*2)
# Modern terrain theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#0a1a0a')
ax.set_facecolor('#0a1a0a')
# Custom terrain colormap - rich greens to snow
colors = ['#0a1a0a', '#0d2a15', '#1a4a2a', '#2a6a3a', '#4a8a4a',
'#6aaa5a', '#8aca6a', '#aaea8a', '#d0f0b0', '#f0fff0', '#ffffff']
cmap = LinearSegmentedColormap.from_list('terrain_dark', colors, N=256)
# Filled contour
cf = ax.contourf(X, Y, Z, levels=18, cmap=cmap)
# Contour lines with labels
cs = ax.contour(X, Y, Z, levels=12, colors='#ffffff', linewidths=0.6, alpha=0.5)
ax.clabel(cs, inline=True, fontsize=8, fmt='%.1f', colors='white')
# Mark peaks with triangles
peak_x = [3, 7, 5, 2, 8]
peak_y = [3, 6, 8, 7, 2]
ax.scatter(peak_x, peak_y, color='#ff6b6b', s=80, marker='^', zorder=5,
edgecolors='white', linewidths=1.5)
# Styled colorbar
cbar = plt.colorbar(cf, ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#0a1a0a')
cbar.set_label('Elevation (km)', fontsize=11, color='#c0e0c0', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#c0e0c0')
cbar.outline.set_edgecolor('#2a4a2a')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#c0e0c0', fontsize=9)
# Labels
ax.set_xlabel('Longitude', fontsize=13, color='#c0e0c0', fontweight='600', labelpad=10)
ax.set_ylabel('Latitude', fontsize=13, color='#c0e0c0', fontweight='600', labelpad=10)
ax.set_title('Mountain Range Topography', fontsize=16, color='white',
fontweight='bold', pad=20)
# Style axes
ax.tick_params(colors='#a0c0a0', labelsize=10, length=0)
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Contour Plot examples
☕