python - Connect data points in the order they were individually plotted - matplotlib -


i trying connect points plotted individually, want connect them in order plotted. have list of numbers referring set of points (ordered pairs). list tells order points should plotted in.

the points in dictionary p. let's p[1], p[2], p[3]. list = (2, 1, 3). want plot line connects p[2] p[1] p[3]. p[i] = (x, y) tuplet x-coordinate x , y-coordinate y.

as have now, plotting points using loop. works, doesn't connect points. great! thanks.

x=[-4, 2, -1, 5] y=[-3, -2, 4, 2] n = 3 #number of cities  p = dict() p_0 = (x[0],y[0])  in range (1,n):     p[i] = (x[i],y[i])  route = (2,1,3) plt.plot([p_0[0]],[p_0[1]]) k in range (0,n-1):     plt.plot([p[route[k]][0]],[p[route[k]][1]]) 

you need provide x coordinates list , y coordinates separate list, when calling plot:

import matplotlib.pyplot plt  x=[-4, 2, -1, 5] y=[-3, -2, 4, 2]  plt.plot(x,y,'b-') 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -