I have the graph y = tan(x) and I want to remove the vertical lines (see below).
Here is my code:
import numpy as np
import matplotlib.p
One could use the definition of the tangent to filter out those points where the cosine of x is close enough to 0.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 4*np.pi, 666)
y = np.tan(x)
y[np.abs(np.cos(x)) <= np.abs(np.sin(x[1]-x[0]))] = np.nan
plt.plot(x, y)
plt.ylim(-3,3)
plt.show()
This works for equally spaced data only.