# How do I make ListPlot join the points in order? [closed]

I gave ListPlot a set of points to plot and join together. The problem is that It's drawing the line in some way other than the order that I input them as.

ListPlot[{{1.0, 4.0}, {0.204237675089357,
4.6056090506695}, {0.742636892489539,
3.76291914168585}, {0.13802394504369,
4.55943856001841}, {-0.806180311546581, 4.88879903402343}},
Joined -> True]


This is the output: I need ListPlot to draw the line in the order that I gave the points. How do I do this?

• It looks to me like it's joining them in the order that you put them in. – march Feb 10 '17 at 6:00
• @march yea, sorry about that. You are correct. I am just a college student in dire need of sleep :p – loltospoon Feb 10 '17 at 6:06
• Does anyone know how to draw the path of these points with arrows? I need to clearly show that this is a path. I know it's obvious in this scenario because no lines overlap but in other cases I will have overlapping lines and I need to show the path from point to point. – loltospoon Feb 10 '17 at 6:08
• Graphics[Arrow /@ Partition[listOfPoints, 2, 1], Axes -> True]. – march Feb 10 '17 at 6:10
• @march , that is nearly perfect. It seems that doing this shifted my point of origin to (1.0,4.3). How can I fix the x-range to [-8,8] and the y-range to [-8,8]? – loltospoon Feb 10 '17 at 6:17

pts = {
{1.0, 4.0},
{0.204237675089357, 4.6056090506695},
{0.742636892489539, 3.76291914168585},
{0.13802394504369, 4.55943856001841},
{-0.806180311546581, 4.88879903402343}};


If you label the points you will see that the line is drawn in the order that the points are entered

ListPlot[pts,
Joined -> True,
Epilog -> (n = 1;
Text[
Style[n++, 14, Bold],
#, {-1, -1}] & /@ pts),
PlotRange -> {3.7, 5}] Just SortBy first element of pair, e.g.:

ListPlot[SortBy[{{1.0, 4.0}, {0.204237675089357,
4.6056090506695}, {0.742636892489539,
3.76291914168585}, {0.13802394504369,
4.55943856001841}, {-0.806180311546581, 4.88879903402343}},
First], Joined -> True] Ordering will work here too,

data = {{1.0, 4.0}, {0.204237675089357,4.6056090506695}, {0.742636892489539,
3.76291914168585}, {0.13802394504369,4.55943856001841}, {-0.806180311546581,
4.88879903402343}};
data[[Ordering[data[[All, All]]]]]


{{-0.80618, 4.8888}, {0.138024, 4.55944}, {0.204238, 4.60561}, {0.742637, 3.76292}, {1., 4.}}

ListPlot[%, Joined -> True, Frame -> True, PlotStyle -> Red] Graphics[Arrow /@ Partition[data[[Ordering[data[[All, All]]]]], 2, 1],Axes -> True] 