I'm trying to add a color BarLegend to a ListLinePlot with multiple lists. With 20+ lists a normal Legend gets long and bulky. Basically, each list line is associated with a different value. I've created a color gradient for the lines using the Hue function but cannot figure out how to get BarLegend to work with ListLinePlot. I've included a sample of the plot I have so far. It would be a much cleaner presentation with a colorbar for the legend. How do I do this, in an elegant way? I'd even settle for a non-elegant method right now. example of what I have

  • $\begingroup$ You should be able to use Epilog (or Prolog) and Inset. Have you already created a BarLegend you want to use? $\endgroup$ – Mr.Wizard Jul 9 '14 at 3:34
  • $\begingroup$ I'm about to go to bed, so I can't give a full answer. But, you want PlotLegends -> BarLegend[{colorFunction, {xmin, xmax}}] as the option. To place it within the plot, wrap BarLegend in Placed. $\endgroup$ – rcollyer Jul 9 '14 at 3:35
ListLinePlot[Table[Accumulate[RandomReal[{-1, 1}, 250]], {10}], 
             PlotStyle -> (Hue[#] & /@ Range[0., .9, .1]), 
             ImageSize -> 500, 
             PlotLegends -> BarLegend[{Hue, {0, 10}}, 10, ColorFunctionScaling -> True]]

enter image description here

  • $\begingroup$ Thanks a bunch. This worked perfectly. $\endgroup$ – mad scientist Jul 9 '14 at 4:50
  • $\begingroup$ @madscientist, glad I could help. Welcome to mma.se. $\endgroup$ – kglr Jul 9 '14 at 11:20

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.