MathGroup Archive 2008

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

Search the Archive

Re: Making nice-looking Legend for Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89667] Re: Making nice-looking Legend for Plot
  • From: "David Park" <djmpark at comcast.net>
  • Date: Tue, 17 Jun 2008 00:37:47 -0400 (EDT)
  • References: <g35g09$9bm$1@smc.vnet.net>

In your particular case, with only two curves, why use a legend at all? Why 
not just directly label the curves as follows?

Plot[{100/x, x/1000 + 1}, {x, 100, 433},
 Epilog -> {Text["NMA", {196.056, 0.587105}],
   Text["DMA", {183.881, 1.27148}]},
 AspectRatio -> 1/2,
 Frame -> True, Axes -> False,
 FrameLabel -> {x, "curves"},
 PlotRange -> {0, 1.5},
 PlotLabel -> Style["NMA and DMA Curves", 12],
 ImageSize -> 400]

I always find the PlotLegend package difficult to use. It is hard to obtain 
precise control. So if one must have a legend it is easier to construct it 
by hand. The advantage is that you know exactly what is happening. Here is 
how I would do it with the Presentations package:

Needs["Presentations`Master`"]

With[
 {location = {.75, .4},
  legendsize = {.20, .25},
  shadowoffset = {.02, -.03},
  laboffset = .04,
  lineoffset = .1,
  linelength = .08,
  lab1yoffset = .17,
  lab2yoffset = .06},
 Draw2D[
  {(* Legend Frame *)
   Rectangle[Scaled[location + shadowoffset],
    Scaled[location + legendsize + shadowoffset]],
   White,
   Rectangle[Scaled[location], Scaled[location + legendsize]],

   (* NMA curve *)
   Blend[{Blue, Black}, .5],
   Draw[100/x, {x, 100, 433}],
   Text["NMA", Scaled[location + {laboffset, lab1yoffset}]],
   Line[{Scaled[location + {lineoffset, lab1yoffset}],
     Scaled[location + {lineoffset + linelength, lab1yoffset}]}],
   Blend[{Red, Black}, .5],

   (* DMA curve *)
   Draw[x/1000 + 1, {x, 100, 433}],
   Text["DMA", Scaled[location + {laboffset, lab2yoffset}]],
   Line[{Scaled[location + {lineoffset, lab2yoffset}],
     Scaled[location + {lineoffset + linelength, lab2yoffset}]}]},

  AspectRatio -> 1/2,
  Frame -> True,
  FrameLabel -> {x, "curves"},
  PlotLabel -> Style["NMA and DMA Curves", 12],
  ImageSize -> 400]
 ]

Legends generally are not good devices even though they are often used. 
Basically they are just another 'plot' that detracts from the main plot. 
That's why it is much better to directly label the curves if you can. Why 
label curves indirectly when you can label them directly? The one place 
where a legend might be useful is for contour or density plots. And there it 
is better to construct your own. And the contour line tooltips on 
Mathematica contour plots are better than any legend. So throw the Legend 
package into the trash can and save yourself a lot of grief.

If there are many intertwined curves then it may be impossible to directly 
label them in a useful manner. That would seem to call for a legend. But how 
does a legend really help there? The main problem is to be able to pick out 
each curve and yet show it in relation to the other curves. I have an 
example in the Presentations package that shows a method for doing this. It 
uses a TabView for multiple graphics and each graphic shows one curve and 
its data points with the other curves in a fainter subdued representation.

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


<lehin.p at gmail.com> wrote in message news:g35g09$9bm$1 at smc.vnet.net...
> Hello,
> I have tried the "Plot Legends Package" for creating simple legend for
> my Plot of two curves. I wish the legend to have minimum size while
> samples of the curves in the legend I want be easily customizable in
> their length to produce nice-looking legend for the plot (from my
> viewpoint). The area taken by the legend I wish to be minimal but
> spaces from edges (relative to the nearest entire objects of the
> legend) I wish also to be easily customizable the same way as shadow
> of the legend. I was surprized that only the shadow may be easily
> customizable. I have spent about hour in making the nice-looking
> legend but I have failed.
> So I would like to take some leadership in making such simple (as I
> thought before) legend. The legend should be placed (for simplicity)
> on the right of the Plot (wihout space) but in the center of it's
> vertical (relative to the center of the legend).
>
> The following is similar to my Plot:
> Plot[{100/x, x/1000 + 1}, {x, 100, 433}, PlotRange -> All]
> These two curves I wish to have short legends {"NMA","DMA"}. I have
> tried all the Options in the "Plot Legends Package" and I (after about
> hour of tries) have produced a nearly above-mentioned legend but the
> length of the samples of the curves I cannot make longer! I have not
> found the way to control the length of the samples of the curves in
> the Plot without breaking all other my progress in making the legend.
>
> If you know an easy way for making the nice-looking legend I will
> appreciate the answer. But may be there is another free package that
> implements this simple and frequently-wanted task?
> 



  • Prev by Date: Re: Re: Re: snippets
  • Next by Date: plot in text mode
  • Previous by thread: Making nice-looking Legend for Plot
  • Next by thread: Re: Making nice-looking Legend for Plot