0
$\begingroup$

I've got a list of points:

figdata = {{67.6769, -1.15057}, {67.9064, -1.30881}, {68.136, -1.01986},
{68.2508, -1.42347}, {68.5951, -1.5152}, {68.7098, -0.946475},
{69.2837, -1.63445}, {69.7428, -1.74453}, {69.9724, -0.905197},
{70.2019, -1.86378}, {70.8905, -0.850158}, {71.0053, -1.96009},
{71.6939, -0.836399}, {72.3826, -2.13438}, {72.6121, -0.822639},
{73.8746, -2.34995}, {73.9894, -0.891437}, {74.4485, -2.4004},
{75.1371, -0.951062}, {75.4815, -2.42792}, {76.1701, -0.987754},
{76.9735, -2.49672}, {77.4326, -1.03362}, {78.236, -2.52423},
{79.0394, -1.10242}, {80.4167, -2.54258}, {80.6462, -1.18039},
{82.2531, -1.26294}, {83.4008, -2.53799}, {84.319, -1.33633},
{85.5815, -1.40054}, {86.9588, -2.54258}, {87.1883, -1.48768},
{88.7951, -1.59317}, {90.0576, -2.54258}, {90.861, -1.67573},
{93.9599, -1.87295}, {92., -2.54258}, {93., -2.54258}, {95.7963,
-2.54258}, {98., -2.54258}, {95.911, -1.95551}, {97.2883, -2.04265},
{99.469, -2.18483}, {100.502, -2.25363}, {100.732, -2.5013},
{101.305, -2.46002}, {101.42, -2.32702}, {101.879, -2.40499}}

I need to plot this data using ListLinePlot so that two neighbouring appear connected with a line. I've tried using the following approach:

 Block[{data = figdata, nearel, datanew0 = {}, i = 1},
 While[Length[data] > 1,
  nearel = 
   Flatten[Nearest[Delete[data, i], data[[i]], 
     DistanceFunction -> "EuclideanDistance"]];
  datanew0 = Append[datanew0, data[[i]]];
  data = Delete[data, i];
  i = Position[data, nearel][[1, 1]]
  ];
 datanew = datanew0
 ]

But, for a reason I don't know, when I do:

p1 = ListLinePlot[datanew, Frame -> True, 
   PlotRange -> {{40, 108}, {-2.6, .8}}, AspectRatio -> 1, 
   FrameStyle -> 15];
p2 = ListPlot[datanew, Frame -> True, 
   PlotRange -> {{40, 108}, {-2.6, .8}}, AspectRatio -> 1, 
   FrameStyle -> 15, PlotStyle -> Red];
Show[p1, p2]

The result i get is:

enter image description here

How would I write a code that solves this problem, and, what is wrong with my piece of code?

$\endgroup$
  • 2
    $\begingroup$ #[[Last@FindShortestTour@Standardize@#]] &@figdata // ListLinePlot? $\endgroup$ – Kuba Feb 2 '19 at 14:36
  • $\begingroup$ Is it enough? mathematica.stackexchange.com/q/47332/5478 $\endgroup$ – Kuba Feb 2 '19 at 14:36
  • $\begingroup$ Yes! Thank you! $\endgroup$ – Musashi Feb 2 '19 at 15:16