1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| """ demo04_contour.py 绘制等高线图 """ import numpy as np import matplotlib.pyplot as plt
n = 500 x, y = np.meshgrid(np.linspace(-3, 3, n), np.linspace(-3, 3, n))
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
plt.figure('Contour', facecolor='lightgray') plt.title('Contour', fontsize=18) plt.grid(linestyle=':') cntr = plt.contour(x, y, z, 8, colors='black', linewidths=.5)
plt.clabel(cntr, inline_spacing=1, fmt='%.2f', fontsize=10)
plt.contourf(x, y, z, 8, cmap='jet') plt.savefig('Contour.png') plt.show()
|