MathGroup Archive 2001

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

Search the Archive

Re: Lines in a legend are too short

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30545] Re: [mg30514] Lines in a legend are too short
  • From: Reinhold Kainhofer <reinhold at kainhofer.com>
  • Date: Tue, 28 Aug 2001 04:54:50 -0400 (EDT)
  • Organization: TU Graz
  • References: <NDBBJGNHKLMPLILOIPPOAEDNCJAA.djmp@earthlink.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David Park wrote:
> 
> There is, to my way of thinking, a minor bug in Legend, in that it does not
> utilize the full width of the key box to draw a line. That makes it
> difficult to obtain long lines in the keys. The reason is that the internals
> have not used a proper AspectRatio for for producing the key box graphics.
> There is a fix, and that is to use ShowLegend and abandon MultipleListPlot.
> (No one really needs MultipleListPlot since it is easy enough to draw the
> lines yourself.)


Thanks to David Park's sample code, I finally wrote my own simple
LegendPlot function which explicitely creates the legend with long lines
in the keys. 

In case somebody else needs this function, too (and also for the record
/ Google-Archiv), here are my functions extending Plot and
MultipleListPlot. They still make some assumptions, like you can't use
Automatic for the PlotStyle option, and the values of the PlotStyle and
PlotLegend options are not wrapped around (i.e. they need to be the same
length or larger than the data). This should be fairly straighforward to
add, but I just needed to get it working. 
I also added an option KeyAspectRation, which can be used to control the
length of the key lines.


SetAttributes[OwnLegendPlot, {HoldAll}]

Options[OwnLegendGeneration]={KeyAspectRatio->0.25};

OwnLegendGeneration[style_List, lg_List, len_Integer, opts___?OptionQ]:=
    Module[{i, ar},
      ar=KeyAspectRatio/.Join[{opts}, Options[OwnLegendGeneration]];
      Table[{Graphics[Flatten[{style[[i]], Line[{{0,0}, {1,0}}]}], 
            AspectRatio->ar], lg[[i]]}, {i, len}]
      ];

OwnLegendPlot[fn_List, r_List, o1___?OptionQ, PlotLegend->lg_, 
    o2___?OptionQ]:=Module[{style, graph, legend, i},
    style=PlotStyle/.Join[{o1, o2}, Options[Plot]];
    graph=
      Plot[fn, r, ##, DisplayFunction:>Identity]&[
        FilterOptions[Plot, o1, o2]];
    legend=
      OwnLegendGeneration[style, lg, Length[fn], 
        FilterOptions[OwnLegendGeneration, o1, o2]];
    ShowLegend[graph, {legend, FilterOptions[Legend, o1, o2]}]
    ]
OwnLegendPlot[fn_, r_List, o1___?OptionQ]:=
    Plot[fn, r, ##]&[FilterOptions[Plot, o1]];


OwnLegendListPlot[fn__List, o1___?OptionQ, PlotLegend->lg_, 
      o2___?OptionQ]:=Module[{style, plotlist, legend, graph, i,j},
      plotlist=
        If[Depth[#]<=2, 
              MapIndexed[Function[{i,j}, {First[j], i}], #], #,
#]&/@{fn};
      style=PlotStyle/.Join[{o1, o2}, Options[Plot]];
      graph=
        Graphics[{Table[
              Join[style[[i]], {Line[plotlist[[i]] ]}],
{i,Length[{fn}]}]}, 
          FilterOptions[Graphics, o1, o2, Sequence@@Options[Plot], 
            Sequence@@Options[Graphics]] ];
      
      legend= OwnLegendGeneration[style, lg,Length[{fn}], 
          FilterOptions[OwnLegendGeneration, o1, o2]];
      ShowLegend[graph, {legend, FilterOptions[Legend, o1, o2]}]
      ];

OwnLegendListPlot[fn__List, o1___?OptionQ]:=
    MultipleListPlot[fn, FilterOptions[MultipleListPlot, o1]];


> These are your style definitions. Your line thicknesses will not really be
> distinguished, at least on my system, but I will ignore that. (You should
> probably use AbsoluteThickness[1] and AbsoluteThickness[2].)

Nope, in the exported EPS file my values look okay, and you can
distinguish the lines then (I admit, on screen there is no visible
difference...). 


Reinhold


-- 
------------------------------------------------------------------
DI Reinhold Kainhofer, Graz, Austria
email: reinhold at kainhofer.com, http://reinhold.kainhofer.com/
 * Mathematics Department, Technical University of Graz
 * Theoretical Physics Department, University of Graz
------------------------------------------------------------------


  • Prev by Date: Re: How do I script the evaluation of a Notebook
  • Next by Date: Re: Exporting code
  • Previous by thread: Lines in a legend are too short
  • Next by thread: Exporting code