我有图y = tan(x)
,我想删除垂直线(见下文)。忽略matplotlib中的连线。 y = tan(x)
这是我的代码:
import numpy as np
import matplotlib.pyplot as plt
# Choose evenly spaced x intervals
x = np.arange(-2*np.pi, 2*np.pi, 0.1)
# plot y = tan(x)
plt.plot(x, np.tan(x))
# Set the range of the axes
plt.axis([-2*np.pi, 2*np.pi, -2, 2])
# Include a title
plt.title('y = tan(x)')
# Optional grid-lines
plt.grid()
# Show the graph
plt.show()
这里是图表(包括不想要的垂直线):
我可以删除垂直线而没有设置适当的间隙进入X间隔?
也许'y [: - 1] [np.diff(y)<0] = np.nan'更容易理解?! – ImportanceOfBeingErnest
@ImportanceOfBeingErnest是更清晰一点,可能更高性能。谢谢! – Suever
我不知道你可以输入值为NaN来制作不连续的曲线。 – Astrophe