python中使用matpltlib画图

import numpy as np
import matplotlib.pyplot as plt

#先定义几组数据
x = [0,1,2,3,4,5,6,7,8,9]
y1 = np.sin(x)
y2 = np.cos(x)
#画图
plt.plot(x, y1, linestyle="--", color="red")
plt.plot(x, y2, linestyle = "-", color= "blue")
#定义横纵轴
plt.xlabel("x")
plt.ylabel("sin & cos")
#定义legend
plt.legend(["sin","cos"],loc = "upper right")
plt.show()

猜你喜欢

转载自blog.csdn.net/m0_37548423/article/details/85175547
今日推荐