1
$\begingroup$

Is there a way to use single ListLinePlot? I don't like my solution.

Here is a minimal example.

SeedRandom@2;
xdata = RandomInteger[5, {3, 20}];
ydata = xdata + 10;
Show[ListLinePlot[xdata, PlotStyle -> ColorData[97, 1]], 
 ListLinePlot[ydata, PlotStyle -> ColorData[97, 2]], PlotRange -> All]

plot

I don't know why this doesn't work

ListLinePlot[{xdata, ydata}, 
 PlotStyle -> {ColorData[97, 1], ColorData[97, 2]}]
$\endgroup$
  • $\begingroup$ {{list1, list2}, {list3, list4}} as first argument does not work; you need to have {list1,list2,list3,list4}. $\endgroup$ – kglr Oct 14 '18 at 3:18
  • $\begingroup$ You have a list of lists of lists, and that is too much nesting for ListLinePlot[] to style properly. As the answers to your question suggest, you need to do some flattening. $\endgroup$ – J. M. will be back soon Oct 14 '18 at 7:00
2
$\begingroup$
ListLinePlot[Riffle[xdata, ydata], PlotStyle -> (ColorData[97] /@ {1, 2})]

enter image description here

A more cumbersome alternative,

ListLinePlot[Join@@{xdata, ydata}, PlotStyle -> (ColorData[97] /@ {1, 1, 1, 2, 2, 2})]

same picture

You can also wrap each data set with Style and assign its color:

ListLinePlot[Join @@ 
  MapIndexed[Function[{x, p}, Style[#, ColorData[97, p[[1]]]] & /@ x], {xdata, ydata}, 1]]

same picture

$\endgroup$
  • $\begingroup$ When I added more option for PlotStyle, it does not work. Say I wanna set AbsoluteThickness@4 $\endgroup$ – OkkesDulgerci Oct 14 '18 at 4:07
  • 1
    $\begingroup$ @Okkes, you can use PlotStyle->(Directive[AbsoluteThickness[4],,ColorData[97]@#]&/@{1,2}) $\endgroup$ – kglr Oct 14 '18 at 4:13
  • $\begingroup$ your work around works only two cluster data set. What if I have three or more data set? $\endgroup$ – OkkesDulgerci Jan 28 '19 at 2:37
  • $\begingroup$ Sorry, your last solution works! But I would like to use custom color for each cluster, say, col0 = {Red, Darker@Green, Blue}; $\endgroup$ – OkkesDulgerci Jan 28 '19 at 2:45
  • 1
    $\begingroup$ ListLinePlot[ Join @@ MapIndexed[ Function[{x, p}, Style[#, col0[[p]]] & /@ x], {A15, A30, A60}, 1]] This works!! $\endgroup$ – OkkesDulgerci Jan 28 '19 at 2:51
1
$\begingroup$
SeedRandom@2;
xdata = RandomInteger[5, {3, 20}];
ydata = xdata + 10;
Show[ListLinePlot[#,PlotStyle -> ColorData[97, #[[1, 1]]]] & /@ {xdata, ydata}, 
PlotRange -> All]  

enter image description here

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