1
$\begingroup$

Assume I have data(sim) below. How can I extract first point on each horizontal line?

sim={{0.0123645, 10}, {0.0315618, 10}, {0.0349631, 10}, {0.0602517, 
  10}, {0.110052, 10}, {0.125536, 10}, {0.126541, 10}, {0.126872, 
  10}, {0.153006, 10}, {0.157659, 10}, {0.158335, 10}, {0.172981, 
  10}, {0.186542, 10}, {0.200192, 10}, {0.214166, 10}, {0.2161, 
  10}, {0.223926, 10}, {0.244128, 10}, {0.27395, 10}, {0.287663, 
  10}, {0.295087, 10}, {0.317831, 10}, {0.331263, 10}, {0.338285, 
  10}, {0.347775, 10}, {0.358619, 10}, {0.381334, 10}, {0.383822, 
  10}, {0.387735, 10}, {0.402114, 10}, {0.450075, 10}, {0.468865, 
  11}, {0.48508, 11}, {0.502013, 11}, {0.51136, 11}, {0.517392, 
  11}, {0.523373, 11}, {0.541651, 11}, {0.543816, 11}, {0.604502, 
  11}, {0.60608, 11}, {0.662307, 11}, {0.664964, 11}, {0.692087, 
  11}, {0.754625, 11}, {0.782756, 11}, {0.792393, 11}, {0.795388, 
  11}, {0.818549, 11}, {0.827898, 11}, {0.838457, 11}, {0.864839, 
  11}, {0.886406, 11}, {0.91586, 12}, {0.933204, 12}, {0.947947, 
  12}, {0.950653, 12}, {0.953183, 12}, {0.97591, 11}, {1.01709, 
  10}, {1.05193, 10}, {1.09514, 10}, {1.12728, 10}, {1.14659, 
  10}, {1.20052, 10}, {1.22754, 11}, {1.24561, 11}, {1.27093, 
  11}, {1.27265, 11}, {1.28367, 11}, {1.28511, 11}, {1.2877, 
  11}, {1.29041, 11}, {1.31259, 12}, {1.31415, 12}, {1.31774, 
  12}, {1.32675, 12}, {1.33307, 12}, {1.34072, 12}, {1.39716, 
  14}, {1.41142, 14}, {1.42015, 14}, {1.42476, 14}, {1.43117, 
  14}, {1.43567, 14}, {1.43754, 14}, {1.45814, 14}, {1.46465, 
  14}, {1.4666, 14}, {1.46877, 14}, {1.47267, 14}, {1.47754, 
  14}, {1.4838, 14}, {1.48614, 14}, {1.51368, 14}, {1.51374, 
  14}, {1.52088, 14}, {1.53724, 14}, {1.5483, 14}, {1.55711, 14}};


ListLinePlot[sim, Epilog -> {Red, PointSize[Small], Point[sim]}, 
 Frame -> True, PlotTheme -> "Detailed", 
 FrameLabel -> {"Time", "Population"}, ImageSize -> Large, 
 InterpolationOrder -> 0]

enter image description here

$\endgroup$
1
  • $\begingroup$ nope, that's not what I want. There are 8 horizontal lines. $\endgroup$ Commented Feb 10, 2018 at 5:28

1 Answer 1

2
$\begingroup$
First /@ SplitBy[sim, Last]

{{0.0123645, 10}, {0.468865, 11}, {0.91586,12}, {0.97591, 11}, {1.01709, 10},{1.22754, 11}, {1.31259, 12}, {1.39716, 14}}

ListLinePlot[sim, 
 Epilog -> {Red, PointSize[Large], Point[First /@ SplitBy[sim, Last]], 
  Green, PointSize[Small], Point[sim]}, 
 Frame -> True, FrameLabel -> {"Time", "Population"}, 
 ImageSize -> Large, InterpolationOrder -> 0]

enter image description here

$\endgroup$
1
  • $\begingroup$ This is what I need. Thanks. $\endgroup$ Commented Feb 10, 2018 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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