zoukankan      html  css  js  c++  java
  • matplotlib 绘制正余弦曲线图

    1、普通风格

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.linspace(0, 2*np.pi, 50)
    y1 = np.sin(x)
    y2 = np.cos(x)
    xticks=[0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi]

    plt.figure('赏尔')

    plt.plot(x, y1, c='g', marker='.', ls='--', label='sin(x)')
    plt.plot(x, y2, 'y.--', label='cos(x)')
    plt.xlabel('x')
    plt.ylabel('sin/cos')
    plt.xticks(xticks,)
    plt.legend()

    plt.show()

    图形

     

     2、添加修饰

    import numpy as np
    import matplotlib.pyplot as plt

    x = np.linspace(0, 2*np.pi, 50)
    y1 = np.sin(x)
    y2 = np.cos(x)
    xticks=[0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi]

    plt.figure('赏尔', facecolor='azure')

    plt.plot(x, y1, c='g', marker='p', ls='--',
             mec='r', mfc='g', ms=7, mew=0.71,
             label='sin(x)')
    plt.plot(x, y2, 'yp--', mec='r', mfc='gold', ms=7, mew=0.72,
             label='cos(x)')
    plt.xlabel('x')
    plt.ylabel('sin/cos')
    plt.xticks(xticks)
    plt.legend()

    plt.show()

    图形

    。。。

    非学无以广才,非志无以成学。
  • 相关阅读:
    Robberies
    Big Event in HDU
    UVA 562 Dividing coins
    Little Rooks
    Bone Collector
    Piggy-Bank
    0-1背包问题之——饭卡
    Monkey and Banana
    The Triangle
    Burning Midnight Oil
  • 原文地址:https://www.cnblogs.com/shanger/p/11976118.html
Copyright © 2011-2022 走看看