美文网首页
matplotlib contours 等高线图

matplotlib contours 等高线图

作者: Do_More | 来源:发表于2017-07-19 08:53 被阅读0次
    image.png
    import matplotlib.pyplot as plt
    import numpy as np
    
    def f(x,y):
        return (1 - x/2 + x**5 + y**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.contourf to filling contours
    # X,Y and value for (X,Y) point
    plt.contourf(X,Y,f(X,Y),8,alpha=0.75,cmap=plt.cm.hot)
    
    # user plt.contourf to add contour lines
    C = plt.contour(X,Y,f(X,Y),8,colors='black',linewidth=.5)
    
    # adding label
    plt.clabel(C,inline=True,fontsize=10)
    
    plt.xticks(())
    plt.yticks(())
    
    plt.show()
    

    相关文章

      网友评论

          本文标题:matplotlib contours 等高线图

          本文链接:https://www.haomeiwen.com/subject/qtgkkxtx.html