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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -