Fix two data lists intertwined
ClearAll[unTangle]
unTangle = Module[{l = #},
l[[All, All, 2]] = Transpose[Sort /@ Transpose[l[[All, All, 2]]]];l] &;
Examples:
Row[{ListLinePlot[{l1, l2}, ImageSize -> Medium],
ListLinePlot[unTangle @ {l1, l2}, ImageSize -> Medium]}, Spacer[10]]
SeedRandom[1]
lsts = MapIndexed[{#2[[1]], #} &] /@ RandomReal[1, {5, 50}];
Row[{ListLinePlot[lsts, ImageSize -> Medium],
ListLinePlot[unTangle @ lsts, ImageSize -> Medium]}, Spacer[10]]
Alternatively,
ClearAll[unIntertwine]
unIntertwine = TemporalData[Transpose[Sort /@ Transpose[#[[All, All, 2]]]],
{#[[1, All, 1]]}] &;
Normal[unIntertwine@{l1, l2}] == unTangle @ {l1, l2}
True
Normal[unIntertwine @ lsts] == unTangle @ lsts
True
ListLinePlot[{l1, l2}]
l0 = Transpose@{l1[[All, 2]], l2[[All, 2]]};
ListLinePlot[{Max /@ l0, Min /@ l0}, DataRange -> {0, 13}]