1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Python 之 matplotlib (九)contours等高线

Python 之 matplotlib (九)contours等高线

时间:2020-07-06 20:57:49

相关推荐

Python 之 matplotlib (九)contours等高线

代码:

import matplotlib.pyplot as pltimport numpy as npdef f(x, y):return (1 - x / 2 + X ** 3) * np.exp(-x ** 2 - y ** 2)n = 256x = 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)pointplt.contourf(X, Y, f(X, Y), 8,alpha=0.75, cmap=plt.cm.hot)# use plt.contour to add contourlinesC = plt.contour(X, Y, f(X, Y), 9, color='balck', linewidth=.5)# adding labelplt.clabel(C, inlines=True)plt.xticks(())plt.yticks(())plt.show()

运行结果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。