def ex2():
x = np.linspace(-10, 10)
# "--" = dashed line
plt.plot(x, np.sin(x), "--", label="sinus")
plt.plot(x, np.cos(x), label="cosinus")
# Show the legend using the labels above
plt.legend()
# The trick here is we have to make another plot on top of the two others.
pi2 = np.pi/2
# Find B such that (-B * pi/2) >= -10 > ((-B-1) * pi/2), i.e. the
# first multiple of pi/2 higher than -10.
b = pi2*int(-10.0/pi2)
# x2 is all multiples of pi/2 between -10 and 10.
x2 = np.arange(b, 10, pi2)
# "b." = blue dots
plt.plot(x2, np.sin(x2), "b.")
plt.show()
评论列表
文章目录