MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: [Mathematica 6] How to add legend to ListLinePlot?

  • To: mathgroup at
  • Subject: [mg76600] RE: [mg76488] [Mathematica 6] How to add legend to ListLinePlot?
  • From: Robert Pigeon <robert.pigeon at>
  • Date: Thu, 24 May 2007 06:16:42 -0400 (EDT)
  • References: <>

Hello Nasser,
I had the same problem with the Legend package, but thanks to some people
here in Mathgroup I could make some sense out of it. So, here is an example
of a simple ListLinePlot with a Legend, nothing sophisticated but just a
start. I think it is the kind of example that should be in the
documentation, but, that is another story! By the way, it works with other
plot command.



a = Table[{i, i^2}, {i, 1, 20}];
b = Table[{i, i^3}, {i, 1, 20}];

 ListLinePlot[{a, b}, 
  PlotStyle -> {Directive[Red], Directive[Blue, Dashed]},
  PlotLabel -> "Test",
  Frame -> True,
  FrameLabel -> {{fonction, func}, {x,(*nothing on top*)}},
  GridLines -> {Automatic, Automatic}, 
  GridLinesStyle -> {Directive[Black], Directive[Green, Dashed]},
  Background -> LightYellow,
  ImageSize -> 600,
  BaseStyle -> {FontSize -> 12, FontWeight -> "Bold"}],

(*Here is the legend *)

  {{Graphics[{Red, Line[{{0, 0}, {5, 0}}]}], 
    "Line a"}, {Graphics[{Directive[Blue, Dashed], 
      Line[{{0, 0}, {5, 0}}]}], "Line b"}},
  LegendSize -> {0.7, 0.2},
  LegendPosition -> {0, -0.85},
  BaseStyle -> {FontSize -> 12, FontWeight -> "Bold"}



As I said, it is a basic example and it is laid out without trying to get
the best!

Hope this help.


Robert Pigeon

-----Original Message-----
From: Nasser Abbasi [mailto:nma at] 
Sent: May-23-07 05:15
To: mathgroup at
Subject: [mg76600] [mg76488] [Mathematica 6] How to add legend to ListLinePlot?


I am drawing few lists in one plot using ListLinePlot.
PlotLegend does not work with ListLinePlot.  Any idea how can one add legend

to listLinePlot?

a = Table[RandomReal[], {10}];
b = Table[RandomReal[], {10}];
ListLinePlot[{a, b}]  (*OK*)
ListLinePlot[{a, b}, PlotLegend -> {"a", "b"}]  (*This is what I'd like to 


  • Prev by Date: Re: Re: Weird result in Mathematica 6
  • Next by Date: Grid
  • Previous by thread: [Mathematica 6] How to add legend to ListLinePlot?
  • Next by thread: Re: [Mathematica 6] How to add legend to ListLinePlot?