数据可视化:matplotlib绘制等高线

ref: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import numpy as np
import matplotlib.pyplot as plt


x = np.arange(0, 10.0, 0.1)
y = np.arange(0, 10.0, 0.1)
X, Y = np.meshgrid(x, y) # 生成x-y网格图
Z = X**1.5 + Y**1.5

plt.figure()
CS = plt.contour(X, Y, Z, levels=6) # 设置距离
plt.clabel(CS, inline=1, fontsize=10, fmt='%d ℃') # 设置标签
plt.savefig('Temp.png', dpi=300, bbox_inches='tight')
plt.show()