MathGroup Archive 2007

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

Search the Archive

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

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

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.

___________________________________________________________

Needs["PlotLegends`"]

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


ShowLegend[
 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

Robert Pigeon


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

Hello;

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?

Needs["PlotLegends`"];
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 
do*)

thanks
Nasser 




  • 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?