MathGroup Archive 2007

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

Search the Archive

RE: Using ShowLegend

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79851] RE: [mg79833] Using ShowLegend
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Tue, 7 Aug 2007 01:24:33 -0400 (EDT)
  • References: <200708060737.DAA26733@smc.vnet.net>

Hi Murray,

> After loading Mathematica 6 package PlotLegends`, the 
> following input gives errors of the form
>    PlotLegends`Legend is not a Graphics primitive or directive.
> 
> Why, and how should one actually do this?  (The Documentation 
> Center pages for ShowLegend and Legend together with the one 
> example on the page for ShowLegend is not sufficient help for me.)
> 
>    ShowLegend[
>      Plot[{x,x^2,x^3},{x,0,1},
>        
> PlotStyle->{Directive[Black,Thick],Directive[Blue,Dashed],Green}
>        ],
>      {Blue,"x"},{Red,"x^2"},{Green,"x^3"}
>    ]
> 
> Note that it does not seem to be possible to use, instead of 
> the ShowLegend wrapper, the PlotLegend option within the Plot 
> expression, as I seem to have no control over the styling of 
> the labeled lines that appear in the legend. (At least 
> neither the documentation for PlotLegend
>   does not indicate how to do this.)

Even in 5.2, the command above has the wrong syntax for ShowLegend which was
ShowLegend[graphics, {legend}].

In any case, for me, the following works, as the general syntax has done in
earlier versions.

Needs["PlotLegends`"]
Plot[{x, x^2, x^3}, {x, 0, 1}, 
 PlotStyle -> {Directive[Black, Thick], Directive[Blue, Dashed], 
   Green}, PlotLegend -> {"x", "x^2", "x^3"}, 
 LegendPosition -> {-0.8, 0}, 
 LegendSize -> {0.3, 0.5},
 LegendShadow -> 0,
 LegendLabel -> Style["Key", Bold, Italic, Blue, Larger]]

Where all numbers (except LegendShadow) are magic -- nothing much has
changed here!

Note though, that in the key, the line for x^2 does not look particularly
dashed.

In 5.2 and earlier, we'd use something like

Plot[{x, x^2, x^3}, {x, 0, 1}, 
 PlotStyle -> {{Black, AbsoluteThickness[5]}, {Blue, 
    Dashing[{.05, .05}]}, Green}, PlotLegend -> {"x", "x^2", "x^3"}, 
 LegendPosition -> {-0.8, 0}, 
 LegendSize -> {0.3, 0.5},
 LegendShadow -> 0,
 LegendLabel -> Style["Key", Bold, Italic, Blue, Larger]]

That is, no Directive[] in our styles if we want to use a Legend.  If this
is true, and I hope it isn't, then it is faintly annoying since Directive[]
was supposed to be a Good Thing(tm), unifying our Graphics styles, and this
example suggests we can't do this.  There is an argument (Dave Park, in
particular) that we shouldn't be using Legends, but some of us can't help
ourselves.  

We can apply Style[] to any particular element of our legend ....

Consistency is the hobgoblin of a tiny mind, but it does make for ease of
use in a complicated system ....

Regards,

Dave.


  • Prev by Date: Re: Documentation Center (v6): do-it-yourself Mathematica
  • Next by Date: Re: gamepad graphics
  • Previous by thread: Using ShowLegend
  • Next by thread: How to extract generated mesh data from a Graphics3D object ?