Matplotlib Lines is plotting extra lines in my plot Matplotlib Lines is plotting extra lines in my plot tkinter tkinter

Matplotlib Lines is plotting extra lines in my plot


It makes sense if you annotate the order in which the line segments are drawn. For example (only plotting the first 10 points, otherwise it becomes a bit of a mess):

import matplotlib.pylab as pllines_x = [-2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 0, 1, 1, 2, -2, 2, -2, -1, -1, 0]lines_y = [0, 1, 1, 2, -2, 2, -2, -1, -1, 0, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2]n = 10pl.figure()pl.plot(lines_x[:n], lines_y[:n])# Number the coordinates to indicate their order:for i in range(len(lines_x[:n])):    pl.text(lines_x[i], lines_y[i], '{}'.format(i))pl.xlim(-3,3)pl.ylim(-3,3)

Results in:

enter image description here

If I increase n, it becomes a larger mess since a number of x,y coordinates are duplicates. So:

  1. Make sure that there are no duplicate coordinates
  2. Make sure that the coordinates are ordered correctly.


Try these sequences instead:

lines_x = [-2, -2, -1, -1,  0,  0,  1,  1,  2, 2, -2]lines_y = [ 0,  1,  1,  2,  2, -2, -2, -1, -1, 0,  0]

Worked for me:

enter image description here

Also I should note that I used simply

In [1]: import matplotlib.pyplot as pltIn [2]: plt.plot(lines_x,lines_y)

So I believe Lines has nothing to do with it.