zoukankan      html  css  js  c++  java
  • 小白学Python——Matplotlib 学习(3) 函数图形

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(-1,1,50)
    y = 2*x + 1
    
    plt.figure()
    plt.plot(x,y)
    plt.show()

     

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(-10,10,50)
    
    y1 = 2*x + 1
    y2 = x**2
    
    plt.figure()
    plt.plot(x,y1)
    plt.plot(x,y2)
    plt.show()
    

      

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(-10,10,50)
    
    y1 = 2*x + 1
    y2 = x**2
    
    plt.figure()
    plt.plot(x,y1,label='straight line')
    plt.plot(x,y2,linestyle='dashed',linewidth=0.5,color='red',marker='.',label='square line')
    plt.legend()
    plt.ylim(-1,4)
    plt.xlim(-3,3)
    ax = plt.gca()
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
    ax.spines['left'].set_position(('data',0))
    ax.spines['bottom'].set_position(('data',0))
    plt.show()

     

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(-10,10,50)
    
    y1 = 2*x + 1
    y2 = x**2
    
    plt.figure()
    plt.plot(x,y1,label='straight line')
    plt.plot(x[:35],y2[:35],linestyle='dashed',linewidth=0.5,color='red',label='square line')
    plt.plot([1,1],[0,3],'k--')
    plt.scatter([1,],[3,],s=20,color='blue')
    plt.annotate('emphasize point',xy=(1,3),xytext=(15,-15),textcoords='offset pixels',arrowprops=dict(arrowstyle='<|-', connectionstyle="arc3,rad=.2"))
    plt.text(-2.4, 6, 'This is some text',fontdict={'size': 16, 'color': 'r'})
    plt.legend(loc='best')
    ax = plt.gca()
    ax.spines['top'].set_color('none')
    ax.spines['right'].set_color('none')
    ax.spines['left'].set_position(('data',0))
    ax.spines['bottom'].set_position(('data',0))
    plt.show()

  • 相关阅读:
    [ZJOI2008]树的统计 树链剖分
    CF915E 动态开线段树
    Poj 2114 Boatherds(点分治)
    Poj 2599 Godfather(树的重心)
    Bzoj 2152: 聪聪可可(点分治)
    Cogs 1714. [POJ1741][男人八题]树上的点对(点分治)
    Cogs 329. K- 联赛(最大流)
    Cogs 731. [网络流24题] 最长递增子序列(最大流)
    Bzoj 2282: [Sdoi2011]消防(二分答案)
    Cogs 732. [网络流24题] 试题库(二分图)
  • 原文地址:https://www.cnblogs.com/adam012019/p/11435708.html
Copyright © 2011-2022 走看看