1
$\begingroup$

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: enter image description here

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

$\endgroup$
  • 2
    $\begingroup$ It looks to me like it's joining them in the order that you put them in. $\endgroup$ – march Feb 10 '17 at 6:00
  • $\begingroup$ @march yea, sorry about that. You are correct. I am just a college student in dire need of sleep :p $\endgroup$ – loltospoon Feb 10 '17 at 6:06
  • $\begingroup$ 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. $\endgroup$ – loltospoon Feb 10 '17 at 6:08
  • 2
    $\begingroup$ Graphics[Arrow /@ Partition[listOfPoints, 2, 1], Axes -> True]. $\endgroup$ – march Feb 10 '17 at 6:10
  • $\begingroup$ @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]? $\endgroup$ – loltospoon Feb 10 '17 at 6:17
3
$\begingroup$
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}]

enter image description here

$\endgroup$
2
$\begingroup$

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]

enter image description here

$\endgroup$
2
$\begingroup$

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]

enter image description here

Adopting @march suggestion,

Graphics[Arrow /@ Partition[data[[Ordering[data[[All, All]]]]], 2, 1],Axes -> True]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.