使用matplotlib进行绘画

来源:互联网 发布:动景眼镜集团知乎 编辑:程序博客网 时间:2024/05/15 23:53
import numpy as npimport matplotlib.pyplot as pltdef simple_line_plot(x,y,figure_no):    plt.figure(figure_no)    plt.plot(x,y)    plt.xlabel("x values")    plt.ylabel("y values")    plt.title("Simple Line")def simple_dots(x,y,figure_no):    plt.figure(figure_no)    plt.plot(x,y,'or')    plt.xlabel("x values")    plt.ylabel("y values")    plt.title("Simple Dots")def simple_scatter(x,y,figure_no):    plt.figure(figure_no)    plt.plot(x,y)    plt.xlabel("x values")    plt.ylabel("y values")    plt.title("Simple scatter")def scatter_with_color(x,y,labels,figure_no):    plt.figure(figure_no)    plt.plot(x,y,c=labels)    plt.xlabel("x values")    plt.ylabel("y values")    plt.title("Scatter with color")if __name__ == "__main__":    plt.close("all")    x = np.arange(1,100)    print(x)    y = np.array([np.power(xx,2) for xx in x])    print(y)    figure_no = 1    simple_line_plot(x,y,figure_no)    figure_no +=1    simple_dots(x,y,figure_no)    x = np.random.uniform(size=100)    y = np.random.uniform(size=100)    figure_no +=1    simple_scatter(x,y,figure_no)    figure_no+=1    label =  np.random.randint(2,size=100)    scatter_with_color(x,y,label,figure_no)    plt.show()

未完。。。

原创粉丝点击