1
$\begingroup$

I have a for loop that produces a few line plots. After it is produced, it is appended together, and I'm using the "Show" command to combine the plots together. As shown in the example code below:

For[l = 1, l <= 21, l++,
  a = ListLinePlot[(mylist[[l]] + l*5)];  
  AppendTo[z, a]];
Show[z, PlotRange -> All] // Print)]

"mylist" is time series data. Looping through it and adding multiples of 5 with the code above allows me to produce a plot as the image below:

enter image description here

I'd like to now combine a few plots that are produced this way in a grid. I have tried using an outer "for" loop, and the command GraphicsGrid, but that doesn't seem to work. Are there any other ways I can go about this? Thanks.

$\endgroup$
  • $\begingroup$ what does mylist look like? $\endgroup$ – kglr Sep 20 '19 at 15:29
  • $\begingroup$ Hi @kglr, I've edited the question above to answer your question of what "mylist" looks like. Thank you. $\endgroup$ – reemodels Sep 20 '19 at 15:35
  • $\begingroup$ thank you very much Jin. $\endgroup$ – kglr Sep 20 '19 at 18:24
3
$\begingroup$
SeedRandom[1]
mylist1 = TimeSeries[#, {5}] & /@ RandomReal[{-1, 1}, {21, 50}];
mylist2 = TimeSeries[#, {20}] & /@ RandomReal[{-10, 10}, {10, 40}];

(1) You can use Table instead of a For loop to construct transformed series, and (2) you can use a single ListLinePlot for mylist1 instead of combining 21 separate plots with Show:

z1a = ListLinePlot[Table[mylist1[[l]] + l*5, {l, 1, 21}] ];
z2a = ListLinePlot[Table[mylist2[[l]] + l*50, {l, 1, 10}] ];
GraphicsGrid[{{z1a}, {z2a}}]

enter image description here

Alternatively, you can use MapIndexed:

z1b = ListLinePlot[MapIndexed[# + #2[[1]] 5 &, mylist1] ];
z2b = ListLinePlot[MapIndexed[# + #2[[1]] 50 &, mylist2] ];
GraphicsGrid[{{z1b}, {z2b}}]

same picture

$\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.