1. 程式人生 > >python學習之matplotlib實戰

python學習之matplotlib實戰

pytho .sh itl linspace atp .py numpy width GC

import numpy as np
def main():
    #print("hello")
    #line
    import matplotlib.pyplot as plt
    x=np.linspace(-np.pi,np.pi,256,endpoint=True)
    #print(x)
    c,s = np.cos(x),np.sin(x)
    plt.figure(1)#繪制第一個圖
    plt.plot(x,c,color="blue",linewidth=1.0,linestyle="-",label="COS", alpha=0.5)#繪制cos
    plt.plot(x,s,"r*", label="SIN") # 繪制sin
    plt.title("cos & sin") #添加標題
    ax=plt.gca()#軸的編輯器
    ax.spines["right"].set_color("none")
    ax.spines["top"].set_color("none")
    ax.spines["left"].set_position(("data",0))
    ax.spines["bottom"].set_position(("data",0))
    plt.show()

if __name__ == ‘__main__‘:
    main()

  

python學習之matplotlib實戰