3
$\begingroup$

Here is a sample of data points:

{{1}, {10.7316, 0.00084028}, {10.7313, 0.011671}, {10.7307, 
0.0224732}, {10.7298, 0.033228}, {10.7287, 0.0439166}, {10.7274, 
0.0545204}, {10.7258, 0.0650205}, {10.724, 0.0753987}, {10.7219, 
0.0856364}, {10.7196, 0.0957157}, {10.7171, 0.105619}, {10.7144, 
0.115327}, {10.7115, 0.124825}, {10.7083, 0.134094}, {10.705, 
0.143117}, {10.7014, 0.151879}, {10.6977, 0.160363}, {10.6937, 
0.168553}, {10.6896, 0.176434}, {10.6853, 0.183992}, {10.6809, 
0.191212}, {10.6762, 0.198081}, {10.6715, 0.204584}, {10.6666, 
0.210709}, {10.6615, 0.216444}, {10.6564, 0.221776}, {10.6511, 
0.226696}, {10.6457, 0.231192}, {10.6402, 0.235255}, {10.6347, 
0.238874}, {10.629, 0.242042}, {10.6233, 0.244751}, {10.6175, 
0.246994}, {10.6117, 0.248763}, {10.6059, 0.250054}, {10.6, 
0.250861}, {10.594, 0.25118}, {10.5881, 0.251008}, {10.5822, 
0.250341}, {10.5762, 0.249179}, {10.5703, 0.24752}, {10.5644, 
0.245363}, {10.5586, 0.24271}, {10.5527, 0.239562}, {10.547, 
0.235922}, {10.5412, 0.231793}, {10.5356, 0.227179}, {10.53, 
0.222085}, {10.5245, 0.216518}, {2}, {10.732, -0.0208292}, 
{10.7328, -0.0316198}, {10.7342, -0.0423423}, {10.736, -0.0529679}
{10.7384, -0.0634674}, {10.7414, -0.0738122}, {10.7449, -0.083974},
{10.7489, -0.0939249}, {10.7534, -0.103637}, {10.7585, -0.113084}, 
{10.7641, -0.122238}, {10.7702, -0.131074}, {10.7769, -0.139566}, 
{10.7841, -0.147689}, {10.7918, -0.155419}, {10.8, -0.162733}, 
{10.8088, -0.169607}, {10.8181, -0.176018}, {10.8279, -0.181946}, 
{10.8382, -0.18737}, {10.8491, -0.192269}, {10.8604, -0.196623}, 
{10.8723, -0.200414}, {10.8847, -0.203623}, {10.8976, -0.206234},
{10.911, -0.208228}, {10.9249, -0.20959}, {10.9392, -0.210304}, 
{10.9541, -0.210354}, {10.9695, -0.209727}, {10.9854, -0.208408},
{11.0018, -0.206384}, {11.0186, -0.203641}, {11.0359, -0.200168},
{11.0538, -0.195951}, {11.072, -0.19098}, {11.0908, -0.185243}, 
{11.11, -0.178728}, {11.1297, -0.171425}, {11.1499, -0.163323}, 
{11.1705, -0.154413}, {11.1916, -0.144684}, {11.2132, -0.134125},
{11.2351, -0.122728}, {11.2576, -0.110483}, {11.2805, -0.0973792},
{11.3038, -0.0834078}, {11.3276, -0.068559}, {11.3518, -0.0528232}, 
{3}, {10.7316, 0.00184063}, {10.7313, 0.0126707}, {10.7307, 0.0234714},
{10.7298, 0.0342238}, {10.7287, 0.0449091}, {10.7274, 0.0555085}, 
{10.7258, 0.0660035}, {10.724, 0.0763756}, {10.7219, 0.0866065}, 
{10.7197, 0.096678}, {10.7172, 0.106572}, {10.7144, 0.116272}, 
{10.7115,  0.125759}, {10.7083, 0.135017}, {10.705, 0.144029}, 
{10.7014, 0.152778}, {10.6977, 0.161249}, {10.6938, 0.169426}, 
{10.6897, 0.177293}, {10.6854, 0.184837}, {10.6809, 0.192042}, 
{10.6763, 0.198894}, {10.6716, 0.205382}, {10.6667, 0.211491}, 
{10.6616, 0.217209}, {10.6565, 0.222525}, {10.6512, 0.227428}, 
{10.6459, 0.231907}, {10.6404, 0.235953}, {10.6349, 0.239556}, 
{10.6292, 0.242707}, {10.6235, 0.2454}, {10.6178, 0.247626}, 
{10.612, 0.249379}, {10.6062, 0.250654}, {10.6003, 0.251446}, 
{10.5944, 0.25175}, {10.5885, 0.251563}, {10.5826, 0.250883}, 
{10.5767, 0.249708}, {10.5708, 0.248036}, {10.5649, 0.245868}, 
{10.5591, 0.243205}, {10.5533, 0.240048}, {10.5476, 0.236399}, 
{10.5419, 0.232263}, {10.5363, 0.227642}, {10.5307, 0.222544}, 
{10.5252, 0.216973}}

In fact there are three sub-lists. Note the three integers 1, 2 and 3 indicating the beginning of each sub-list. Please note that the real data file contains about 1000 sub-lists.

My questions are the following:

(a). How to ListPlot all three sub-lists together in a single plot with option Joined -> True. Of course the last point of sub-list 1 should not be connected with the first point of sub-list 2, etc.

(b). Is there a way to pick and ListPlot with Joined -> True let's say sub-list 1 or sub-lists 1 and 3 together?

Any suggestions?

Many thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ Just do something like {l1, l2, l3} = Reap[Module[{idx = 0}, Scan[If[MatchQ[#, {_Integer}], idx++, Sow[#, idx]] &, lists]]][[2]]; where list is your list, then treat the l1,l2,l3... as desired in the ListPlot $\endgroup$ – ciao Sep 26 '15 at 8:42
  • 3
    $\begingroup$ Alternatively, you can also obtain your lists free of the headers as follows: {list1, list2, list3} = SplitBy[list, Dimensions][[2 ;; ;; 2]] $\endgroup$ – MarcoB Sep 26 '15 at 8:54
  • $\begingroup$ @MarcoB: Clever. $\endgroup$ – ciao Sep 26 '15 at 8:56
  • $\begingroup$ @ciao The real data file contains about 1000 sub-lists. So, I need a more automatic solution for plotting all the sub-lists together or picking some of them (let's say 1, 48 and 521). $\endgroup$ – Vaggelis_Z Sep 26 '15 at 8:57
  • $\begingroup$ @MarcoB Please see the above comment. My problem is not how to remove the headers. $\endgroup$ – Vaggelis_Z Sep 26 '15 at 8:58
3
$\begingroup$

Using the comments from @MarcoB and @ciao I found a working solution.

l = SplitBy[data, Dimensions][[2 ;; ;; 2]];
n = Length[l];
data2 = l[[n]];
L0 = ListPlot[data2, PlotStyle -> {Blue}, Joined -> True]

Now if we want to plot the sub-list with odd or even headers we take

rg = Range[n];
odds = rg[[;; ;; 2]]
evens = rg[[2 ;; ;; 2]]
$\endgroup$
0
$\begingroup$

Split data into sublists of runs of successive elements with the same length and group them in pairs

SplitBy[data, Length] // Partition[#, 2, 2] &

then build rules {{1}-> sublist1, {2}->sublist2,..., {n}->sublistn}

Map[Rule[Flatten[#[[1]]], #[[2]]] &, SplitBy[data, Length] // Partition[#, 2, 2] &]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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