3
$\begingroup$

I have two lists of Dimension[list1] = {6,110} similarly for list2.

I would like to ListPlot[{list1, list2}] and then shade the region between the curve corresponding to the nth line of list1 and the curve corresponding to the nth line of list2, (without really using Show unless its the absolute final step).

The object temp ={list1,list2} has Dimension[temp] = {2,6,110} which cannot be ListPlotted straight away.

Any suggestions?

$\endgroup$
6
  • 1
    $\begingroup$ does this give what you need: ListPlot[Join[list1, list2], Joined -> True, Filling -> Thread[Range[6] -> List /@ Range[7, 12]]]? $\endgroup$
    – kglr
    Feb 1, 2018 at 16:49
  • $\begingroup$ Holy cow this looks interesting, let me get back to you. $\endgroup$ Feb 1, 2018 at 16:52
  • $\begingroup$ Is it possible to have the same color for the same curve? Your current code is beautiful but it gives two different colors for the curves that constitutes the boundary of the shaded region. $\endgroup$ Feb 1, 2018 at 17:14
  • $\begingroup$ It would be nice if (1 and 7), (2 and 8),...(6 and 12) pairwise had the same color. Is this possible to implement? $\endgroup$ Feb 1, 2018 at 17:32
  • $\begingroup$ Faq, I posted the comment as an answer with the styling feature added. $\endgroup$
    – kglr
    Feb 1, 2018 at 17:33

1 Answer 1

4
$\begingroup$
list1 = Mean[3 # + RandomVariate[NormalDistribution[2, 1], {6, 110}]] & /@ Range[6];
list2 = list1 + 3 (StandardDeviation /@ list1);
temp = {list1, list2};
colors = ColorData[97, "ColorList"][[ ;; 6]];
filling = Thread[Range[6] -> List /@ Range[7, 12]];

ListLinePlot[Join @@ temp,  PlotStyle -> colors, Filling -> filling, 
 PlotLegends ->  SwatchLegend[colors, StringJoin["pair", #] & /@ (ToString /@ Range[6]), 
   LegendLayout -> {"ReversedColumn", 1}], ImageSize -> 500 ]

enter image description here

Update:

is there a way to say let curve 1 in the numeration of filling be dashed while curve 7 solid. Meanwhile curve 2 solid while curve 8 dashed and so on?

Instead of PlotStyle -> colors above use PlotStyle -> styles where

 styles = Join[Directive[#, Dashed]& /@ #, #]& @colors

to get

enter image description here

$\endgroup$
6
  • $\begingroup$ 😳 Let me try this out a minute. $\endgroup$ Feb 1, 2018 at 17:33
  • $\begingroup$ That's a beautiful solution! $\endgroup$ Feb 1, 2018 at 19:09
  • $\begingroup$ @Faq, glad it was useful. Thank you for the accept. $\endgroup$
    – kglr
    Feb 1, 2018 at 19:34
  • $\begingroup$ One final follow up, is there a way to say let curve 1 in the numeration of filling be dashed while curve 7 solid. Meanwhile curve 2 solid while curve 8 dashed and so on? $\endgroup$ Feb 1, 2018 at 19:57
  • 1
    $\begingroup$ Faq, please see the update. $\endgroup$
    – kglr
    Feb 1, 2018 at 20:08

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.