Use Python to draw sin (x) and COS (x) in the same legend

feiwen110 2022-05-14 13:50:14 阅读数:241

usepythondrawsincos

Don't talk much , Go straight to the code :

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y1, label='sin')
plt.plot(x, y2, linestyle='--', label='cos')
plt.xlabel('x')
plt.ylabel('y')
plt.title('sin & cos')
plt.legend()
plt.show()

 

版权声明:本文为[feiwen110]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/134/202205141331249219.html