01
气象气压分布等高线
用 contourf 与 contour 绘制填充等高线,并添加数值标签与色条。
查看 Python 代码 +
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) + np.cos(Y)
plt.figure(figsize=(8, 6))
contourf = plt.contourf(
X, Y, Z,
levels=15,
cmap='coolwarm'
)
contour = plt.contour(
X, Y, Z,
levels=15,
colors='black',
linewidths=0.5
)
plt.clabel(contour, inline=True, fontsize=8)
plt.colorbar(contourf, label='气压值')
plt.title('气象气压分布(等高线图)')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
