Python 之 matplotlib (九)contours等高线

xiaoxiao2021-02-28  12

代码:

import matplotlib.pyplot as plt import numpy as np def f(x, y): return (1 - x / 2 + X ** 3) * np.exp(-x ** 2 - y ** 2) n = 256 x = np.linspace(-3, 3, n) y = np.linspace(-3, 3, n) X, Y = np.meshgrid(x, y) # 网格输入值 # use plt.contour to filling contours # X,Yand value for (X,Y)point plt.contourf(X, Y, f(X, Y), 8, alpha=0.75, cmap=plt.cm.hot) # use plt.contour to add contourlines C = plt.contour(X, Y, f(X, Y), 9, color='balck', linewidth=.5) # adding label plt.clabel(C, inlines=True) plt.xticks(()) plt.yticks(()) plt.show()

运行结果:

转载请注明原文地址: https://www.6miu.com/read-2000303.html

最新回复(0)