代码语言:javascript复制
import numpy as np
import matplotlib
matplotlib.use(“TkAgg”)
import matplotlib.pyplot as plt
def height(x,y):
#the height function
return(1-x/2 x5 y3)*np.exp(-x2-y2)
n=256
x=np.linspace(-3,3,n)
y=np.linspace(-3,3,n)
X,Y=np.meshgrid(x,y) #把X,Y传入网格中,X.shape=nn,Y.shape=nn
use plt.contourf to filling contours
代码语言:javascript复制#X,Y and value for (X,Y) point
plt.contourf(X,Y,height(X,Y),8,alpha=0.75,cmap=plt.cm.hot)
#8:8 2=10,将高分为10部分,
#alpha:透明度
#cmap:color map
#use plt.contour to add contour lines
C=plt.contour(X,Y,height(X,Y),8,colors=“black”,linewidth=.5)
#adding label
plt.clabel(C,inline=True,fontsize=10)
#clabel:cycle的label,inline=True表示label在line内,fontsize表示label的字体大小
plt.show()