python matplotlib 绘制等高线

    技术2024-10-22  30

    python matplotlib 绘制等高线

    """ 绘制等高线 """ import numpy as np import matplotlib.pyplot as mp # 准备数据 num = 500 x, y = np.meshgrid(np.linspace(-3, 3, num), np.linspace(-3, 3, num)) print(x[:4], "-->X") print(y[:4], "-->y") z = (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2) * 10 # 创建窗口 mp.figure("Contour", facecolor="lightgray", figsize=(8, 6)) mp.title("Contour", fontsize=20) # 等高线 颜色映射 mp.contourf(x, y, z, 10, cmap="jet") # 绘制等高线 cnt_r = mp.contour(x, y, z, 10, colors="b", linewidths=0.5) mp.clabel(cnt_r, inline_spacing=0.1, fmt="%.2f", fontsize=8) # 等高线标签值 mp.show()

    Processed: 0.010, SQL: 9