1
$\begingroup$

The question is how to sequentially execute Show with two streams of input. The first is graphics object stream and the second is a character stream for supplying labelling for the graphics. I tried

ss={{ListPlot[x1]},{ListPlot[x2],...};labelling={aa,bb,cc,dd....};
Map[Show[#1,PlotLabel->StringJoin[#2,"...","..."]]&,{ss,labelling}]
$\endgroup$
  • $\begingroup$ I tried both Map and MapThread to inconsistent results. It became consistent when I put the labelling elements into individual curly brackets, i.e., labelling={{aa},{bb},{cc},(dd)) Wonder why is this the case? $\endgroup$ – Z Ming Ma Jun 13 at 0:23
2
$\begingroup$

You can use MapThread:

SeedRandom[1]
{x1, x2, x3, x4} = RandomInteger[100, {4, 30}];

ss = ListPlot /@ {x1, x2, x3, x4}; 

labeling = {"aa", "bb", "cc", "dd"}; 

MapThread[Show[#, PlotLabel -> StringJoin[#2, "...", "..."]] &, {ss, labeling}]

enter image description here

Alternatively, you can Apply the function Show[...] on Transpose[{ss, labeling}]:

Show[#1, PlotLabel -> StringJoin[#2, "...", "..."]] & @@@ Transpose[{ss, labeling}]

same picture

You can also use ListPlot[...] in the first argument of MapThread:

datasets = {x1, x2, x3, x4};
colors = {Red, Green, Blue, Orange};
joined = {True, False, False, True};

MapThread[ListPlot[#, Joined -> #4, 
   PlotLabel -> StringJoin[#2, "...", "..."], PlotStyle -> #3] &, 
 {datasets, labeling, colors, joined}]

enter image description here

Again, you can Apply the function ListPlot[...] on tuples of parameters to get the same result:

ListPlot[#, Joined -> #4, 
   PlotLabel -> StringJoin[#2, "...", "..."], PlotStyle -> #3] & @@@ 
 Transpose[{datasets, labeling, colors, joined}]

same picture

| improve this answer | |
$\endgroup$
  • $\begingroup$ I tried both Map and MapThread to inconsistent results. It became consistent when I put the labelling elements into individual curly brackets, i.e., labelling={{aa},{bb},{cc},(dd)) Wonder why is this the case? $\endgroup$ – Z Ming Ma Jun 13 at 0:22

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.