20.python-matplotlib

it2022-05-05  49

#matplotlib import matplotlib import numpy as np import matplotlib.pyplot as plt def simple_line(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.scatter(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.scatter(x,y,c=labels) plt.xlabel('x values') plt.ylabel('y values') plt.title('Scatter with color') figure_no=1 x=np.arange(20) y=np.array([np.power(xx,2) for xx in x]) simple_line(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) labels=np.random.randint(2,size=100) figure_no+=1 scatter_with_color(x,y,labels,figure_no) plt.show()

转载于:https://www.cnblogs.com/wjc920/p/9256144.html


最新回复(0)