Hello,
I want to plot multiple lines using matplotlib.pyplot.plot using the None separator: when i zoom or plot lines that go far away from the axis limits, they their direction is changed. I encounter a bug shown by the folowing code:
import matplotlib.pyplot as plt
Single line
x = [0., 1., 1., 0., 0.]
y = [0., 0., 1., 1., 0.]
Multiple lines separated by None
x2 = [0., 1., None ,1., 0.]
y2 = [0., 0., None, 1., 1.]
Let’s plot
fig = plt.figure(0)
plt.clf()
ax = fig.add_subplot(121)
plt.title(‘No zoom’)
plt.xlim([-1, 2])
plt.ylim([-1, 2])
plt.plot(x,y, ‘bo-’, label = ‘This is ok’)
plt.plot(x2,y2, ‘ro-’, label = ‘This is not ok’)
plt.legend()
ax = fig.add_subplot(122)
plt.title(‘With zoom one a corner’)
plt.xlim([-.05, .1])
plt.ylim([.95, 1.05])
plt.plot(x,y, ‘bo-’, label = ‘This is ok’)
plt.plot(x2,y2, ‘ro-’, label = ‘This is not ok’)
plt.legend()
plt.show()
I tried several approaches to solve the problem but never succeeded. I don’t wich to use 2D arrays or LineCollections because this solution is faster and allows the declaration of all lines with a single label and color. Has anyone any idea ?
Regards.