python学习之matplotlib实战

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()

  

猜你喜欢

转载自www.cnblogs.com/gylhaut/p/9094815.html