3
$\begingroup$

I have multiple series, which I want to plot using ListLinePlot and Map. For example

datamatrix = RandomInteger[{1, 9}, {20, 3}];
ListLinePlot /@ Transpose[datamatrix]

By doing this, I can plot all three series. I am trying to specify different plotting options for my different graphs. For example, I want to apply different titles (Title1, Title2, Title3 for illustration purpose) and different colors to my graphs (Red,Green and Pink for illustration purpose). If possible, I want to specify different DataRange.

Please, help. Simpler the answer, the better. Thank you in advance.

$\endgroup$

2 Answers 2

4
$\begingroup$
datamatrix = RandomInteger[{1, 9}, {20, 3}];
styles = {Directive[Thick, Red], Directive[Thick, Green],  Directive[Thick, Blue]};
titles = ToString /@ {title1, title2, title3};
ListLinePlot[#, PlotStyle -> #2, PlotLabel->#3] & @@@ 
    Transpose[{Transpose[datamatrix], styles,titles}]

enter image description here

ListLinePlot[#, PlotStyle -> Directive[Thick, Hue[RandomReal[]]]] & /@Transpose[datamatrix]

enter image description here

$\endgroup$
2
  • $\begingroup$ @ kguler Thanks. You guys are smart. I always imagine and post a question, somebody like you will answer. Thanks for your contribution to this forum. $\endgroup$
    – ramesh
    Nov 30, 2014 at 17:30
  • 2
    $\begingroup$ @rka, thank you for the kind words. $\endgroup$
    – kglr
    Nov 30, 2014 at 17:33
2
$\begingroup$

An alternative approach would be to use MapThread, which avoids one Transpose. I also created the titles a different way using Array, purely for didactic purposes of showing how to automate these things. Note that you can avoid using Directive in this way by setting BaseStyle.

datamatrix = RandomInteger[{1, 9}, {20, 3}]; 
colors = {Red, Green, Blue}; 
titles =  Array["Title " <> ToString[#] &, 3]; 
Grid[{MapThread[ListLinePlot[#, PlotStyle -> #2, PlotLabel -> #3, 
     BaseStyle -> Thick] &, {Transpose[datamatrix], colors, titles} ]}, 
     ItemSize -> Full]

enter image description here

$\endgroup$
1
  • $\begingroup$ @ Verbeia, thank you for taking time to answer this question. $\endgroup$
    – ramesh
    Dec 1, 2014 at 3:13

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.