2
$\begingroup$

I have this data

data={{-0.7, -0.457884}, {-0.63, -0.360238}, {-0.56, -0.271474}, {-0.49, \
-0.191365}, {-0.42, -0.11963}, {-0.35, -0.0559177}, {-0.28, 
  0.000205128}, {-0.21, 0.0492615}, {-0.21, -0.235869}, {-0.14, 
  0.0918707}, {-0.14, -0.213311}, {-0.07, 
  0.128747}, {-0.07, -0.188571}, {1.66533*10^-16, 
  0.16069}, {1.66533*10^-16, -0.16069}, {0.07, -0.128747}, {0.07, 
  0.188571}, {0.14, -0.0918707}, {0.14, 
  0.213311}, {0.21, -0.0492615}, {0.21, 
  0.235869}, {0.28, -0.000205128}, {0.35, 0.0559177}, {0.42, 
  0.11963}, {0.49, 0.191365}, {0.56, 0.271474}, {0.63, 
  0.360238}, {0.7, 0.457884}};    

which is two branches as can be seen in ListPlot

ListPlot@data

enter image description here

How can we arrange the data and preserve these two branches as lines using ListLinePlot? I tried Sort but did not work.

ListLinePlot@Sort@data       

enter image description here

Update--------------

the solution provided by @David Keith is great but I noticed that with increasing the data points it is not working perfectly.

largdata={{-0.7, -0.457884}, {-0.69, -0.443384}, {-0.68, -0.429068}, {-0.67, \
-0.414936}, {-0.66, -0.400988}, {-0.65, -0.387222}, {-0.64, \
-0.373639}, {-0.63, -0.360238}, {-0.62, -0.347019}, {-0.61, \
-0.33398}, {-0.6, -0.321121}, {-0.59, -0.308441}, {-0.58, -0.295941}, \
{-0.57, -0.283618}, {-0.56, -0.271474}, {-0.55, -0.259505}, {-0.54, \
-0.247713}, {-0.53, -0.236096}, {-0.52, -0.224654}, {-0.51, \
-0.213385}, {-0.5, -0.202289}, {-0.49, -0.191365}, {-0.48, \
-0.180612}, {-0.47, -0.170029}, {-0.46, -0.159615}, {-0.45, \
-0.149369}, {-0.44, -0.13929}, {-0.43, -0.129378}, {-0.42, -0.11963}, \
{-0.41, -0.110046}, {-0.4, -0.100625}, {-0.39, -0.0913658}, {-0.38, \
-0.0822665}, {-0.37, -0.0733263}, {-0.36, -0.0645438}, {-0.35, \
-0.0559177}, {-0.34, -0.0474467}, {-0.33, -0.0391293}, {-0.32, \
-0.0309641}, {-0.31, -0.0229496}, {-0.3, -0.0150843}, {-0.29, \
-0.00736655}, {-0.28, 0.000205128}, {-0.27, 0.00763243}, {-0.26, 
  0.014917}, {-0.25, 0.0220607}, {-0.24, 
  0.0290651}, {-0.24, -0.245111}, {-0.23, 
  0.0359322}, {-0.23, -0.24205}, {-0.22, 
  0.0426637}, {-0.22, -0.23897}, {-0.21, 
  0.0492615}, {-0.21, -0.235869}, {-0.2, 
  0.0557276}, {-0.2, -0.232743}, {-0.19, 
  0.0620639}, {-0.19, -0.22959}, {-0.18, 
  0.0682725}, {-0.18, -0.226406}, {-0.17, 
  0.0743554}, {-0.17, -0.223189}, {-0.16, 
  0.0803146}, {-0.16, -0.219937}, {-0.15, 
  0.0861523}, {-0.15, -0.216645}, {-0.14, 
  0.0918707}, {-0.14, -0.213311}, {-0.13, 
  0.0974719}, {-0.13, -0.209933}, {-0.12, 
  0.102958}, {-0.12, -0.206508}, {-0.11, 
  0.108332}, {-0.11, -0.203032}, {-0.1, 
  0.113595}, {-0.1, -0.199503}, {-0.09, 
  0.118751}, {-0.09, -0.195919}, {-0.08, 
  0.1238}, {-0.08, -0.192275}, {-0.07, 
  0.128747}, {-0.07, -0.188571}, {-0.06, 
  0.133592}, {-0.06, -0.184802}, {-0.05, 
  0.13834}, {-0.05, -0.180966}, {-0.04, 
  0.142991}, {-0.04, -0.177061}, {-0.03, 
  0.14755}, {-0.03, -0.173084}, {-0.02, 
  0.152017}, {-0.02, -0.169031}, {-0.01, 
  0.156396}, {-0.01, -0.164901}, {0, 
  0.16069}, {0, -0.16069}, {0.01, -0.156396}, {0.01, 
  0.164901}, {0.02, -0.152017}, {0.02, 
  0.169031}, {0.03, -0.14755}, {0.03, 
  0.173084}, {0.04, -0.142991}, {0.04, 
  0.177061}, {0.05, -0.13834}, {0.05, 
  0.180966}, {0.06, -0.133592}, {0.06, 
  0.184802}, {0.07, -0.128747}, {0.07, 
  0.188571}, {0.08, -0.1238}, {0.08, 
  0.192275}, {0.09, -0.118751}, {0.09, 
  0.195919}, {0.1, -0.113595}, {0.1, 
  0.199503}, {0.11, -0.108332}, {0.11, 
  0.203032}, {0.12, -0.102958}, {0.12, 
  0.206508}, {0.13, -0.0974719}, {0.13, 
  0.209933}, {0.14, -0.0918707}, {0.14, 
  0.213311}, {0.15, -0.0861523}, {0.15, 
  0.216645}, {0.16, -0.0803146}, {0.16, 
  0.219937}, {0.17, -0.0743554}, {0.17, 
  0.223189}, {0.18, -0.0682725}, {0.18, 
  0.226406}, {0.19, -0.0620639}, {0.19, 
  0.22959}, {0.2, -0.0557276}, {0.2, 
  0.232743}, {0.21, -0.0492615}, {0.21, 
  0.235869}, {0.22, -0.0426637}, {0.22, 
  0.23897}, {0.23, -0.0359322}, {0.23, 
  0.24205}, {0.24, -0.0290651}, {0.24, 
  0.245111}, {0.25, -0.0220607}, {0.26, -0.014917}, {0.27, \
-0.00763243}, {0.28, -0.000205128}, {0.29, 0.00736655}, {0.3, 
  0.0150843}, {0.31, 0.0229496}, {0.32, 0.0309641}, {0.33, 
  0.0391293}, {0.34, 0.0474467}, {0.35, 0.0559177}, {0.36, 
  0.0645438}, {0.37, 0.0733263}, {0.38, 0.0822665}, {0.39, 
  0.0913658}, {0.4, 0.100625}, {0.41, 0.110046}, {0.42, 
  0.11963}, {0.43, 0.129378}, {0.44, 0.13929}, {0.45, 
  0.149369}, {0.46, 0.159615}, {0.47, 0.170029}, {0.48, 
  0.180612}, {0.49, 0.191365}, {0.5, 0.202289}, {0.51, 
  0.213385}, {0.52, 0.224654}, {0.53, 0.236096}, {0.54, 
  0.247713}, {0.55, 0.259505}, {0.56, 0.271474}, {0.57, 
  0.283618}, {0.58, 0.295941}, {0.59, 0.308441}, {0.6, 
  0.321121}, {0.61, 0.33398}, {0.62, 0.347019}, {0.63, 
  0.360238}, {0.64, 0.373639}, {0.65, 0.387222}, {0.66, 
  0.400988}, {0.67, 0.414936}, {0.68, 0.429068}, {0.69, 
  0.443384}, {0.7, 0.457884}}          

using FindClusters

clusters = 
  FindClusters[Chop@engT[Length@evnls], 2, Method -> "SpanningTree"];
ListLinePlot[clusters];    

enter image description here

$\endgroup$
0

1 Answer 1

12
$\begingroup$
clusters = FindClusters[data, 2, Method -> "SpanningTree"];
ListLinePlot[clusters, PlotMarkers -> {Automatic, 10}]

enter image description here

$\endgroup$
3
  • $\begingroup$ that is GREAT! I noticed that if data points increased it is not working perfectly, kindly see the update. $\endgroup$
    – MMA13
    Apr 24 at 6:41
  • 1
    $\begingroup$ @MMA13, try Method -> "Agglomerate". $\endgroup$
    – Domen
    Apr 24 at 7:45
  • $\begingroup$ @Domen, it works. Thanks! $\endgroup$
    – MMA13
    Apr 24 at 7:49

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