MathGroup Archive 2007

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

Search the Archive

RE: Mathematica 6.0 - Legend

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75958] RE: [mg75861] Mathematica 6.0 - Legend
  • From: Robert Pigeon <robert.pigeon at videotron.ca>
  • Date: Mon, 14 May 2007 03:34:15 -0400 (EDT)
  • References: <200705120704.DAA23845@smc.vnet.net>

Hi David,
	Thanks for the reply! And, yes, it might be just me... :) 
But my question was with Mathematica 6.0 ....  Your examples are not working
in ver. 6.0 because the Legend package was changed. They do work with 5.2. I
was using Dave Park's DrawGraphics package for my graphics and legends, but
now the package is not working properly anymore.

So my question is still open :) 

How can we add legends to a plot (ListPlot or ListLinePlot) to identify
curves ? 

Robert

Robert Pigeon


-----Original Message-----
From: David Annetts [mailto:davidannetts at aapt.net.au] 
Sent: May-13-07 08:35
To: 'Robert Pigeon'; mathgroup at smc.vnet.net
Subject: [mg75958] RE: [mg75861] Mathematica 6.0 - Legend

Hi Robert,

>   I want to create a Legend on a ListLinePlot I made.  I have 
> 4 data groups I plot on one graph and I want to identify each 
> one by its colour and a name.
> 
>   I read about the Legend Package, but it seems, if I 
> understand correctly, to work only with Plot like graphs. I 
> do not understand why it is so difficult (it seems to me 
> anyway) to add a legend to a graph. It is common practice in 
> science to identify a plot with a legend, so others can 
> understand your graphics. With the Plot command it seems 
> straight forward to do this with PlotLegend (mind you I do 
> not see how I can move the legend around...). Why this 
> package is not available with all other graphics tools, like 
> ListPlot, ListLinePlot,....
> 
>  
> 
> Or maybe it is just me ...  J

It might just be you ....:)  For 5.2 and earlier, Legends can be moved using
the directive LegendPosition->{x, y}.  For other plotting commands, Legends
can be used with the command ShowLegend.  It's tedious, but not particularly
difficult.  

I hope that Legend use with 6.0 is much less tedious.

Anyway, given
	
	data = Random[] & /@ Range[32];
	p1 = ListPlot[data];

We can define a line using

	lin = {Graphics[Line[{{-1, 0}, {0, 0}}]]};

And a legend using

	lgd = {Transpose[{lin, {"Legend"}}],
      LegendLabel -> StyleForm["Label", FontWeight -> "Bold"],
      LegendOrientation -> Vertical,
      LegendSize -> {.4, .2},
      LegendShadow -> .01,
      LegendPosition -> {-.2, -.95}
      };

We use them together with ShowLegend[] as

	ShowLegend[p1, lgd];

The tedium comes when trying to position the legend, but the two positions
below should get you started.

	LegendPosition -> {-.8, .35} 	(* top left *)
	LegendPosition -> {.5, -.5} 	(* bottom right *)

For graphs of more than one data set, you'll need muliple Legend entries,
for example, given

	data = {Random[], Random[]} & /@ Range[32];
	data = Transpose[data];
	p1 = MultipleListPlot[data, PlotStyle -> {Red, Blue}, SymbolShape ->
None];

One Legend might be

	lin = Graphics[{#, Line[{{-1, 0}, {0, 0}}]}] & /@ {Red, Blue};
	
	lgd = {Transpose[{lin, {"Curve 1", "Curve 2"}}],
      LegendLabel -> StyleForm["Comparison", FontWeight -> "Bold"],
      LegendOrientation -> Vertical,
      LegendSize -> {.4, .2},
      LegendShadow -> .01,
      LegendPosition -> {.5, -.5}
      };
	
	ShowLegend[p1, lgd];

Regards,

Dave.



  • Prev by Date: Re: Re: Making sense of Directive[ ]
  • Next by Date: Re: v6 resizing palettes on a mac
  • Previous by thread: RE: Mathematica 6.0 - Legend
  • Next by thread: Re: Mathematica 6.0 - Legend