MathGroup Archive 2005

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

Search the Archive

Re: ShowLegend....

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53659] Re: [mg53617] ShowLegend....
  • From: "David Annetts" <davidannetts at ihug.com.au>
  • Date: Fri, 21 Jan 2005 06:37:27 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Peter,

> There has to be an easier way to do this....
> 
> I was trying to figure out how to use showlegend, and here's 
> what I came out with....
> 
> (* plot2 and plot3 are two different plots *)
> 
> plotX = Show[ {plot2 , plot3}, PlotRange -> {{ -0.4, 0.4}, {-1, 10}}]
> 
> legend = ShadowBox[ {-0.4, 6}, {0.3, 3}, ShadowBackground -> 
> GrayLevel[ 0.5], ShadowOffset -> {0.025, -0.5}];
> 
> showlegend = Show[ plotX, Graphics[{legend , { Text["Normal - 
> solid", {-.375, 6.775}, {-1.0, 0}], Text["Data - dashed", 
> {-.375, 7.775}, {-1.0, 0}] } } ] ]
> 
> That is way to much code to just add a legend to a graph.

You can use the Graphics`Legend package, to place legend on graphs, but,
IMHO, it's just as messy!  This package is loaded when (if?) you load
Graphics`MultipleListPlot.

> Is there a faster/easier way to do this?
> Is there a way that the legend also includes an example of 
> the line / linestyle?  

Look at the code below.  

Define
SetOptions[MultipleListPlot,
    PlotRange -> {{-1, 2.5}, {-1, 5}},
    SymbolStyle -> None,
    SymbolShape -> None,
    DisplayFunction -> Identity,
    FrameTicks -> {LogScale, LogScale, None, None}
    ];
cmp = {8, 9, 2, 16, 1};
col = {Black, Red, Green, Blue, Cyan, Magenta};
titl = {
      "Dykes only",
      "East dyke only",
      "Full (Trg @ 138 m)",
      "Full (Trg @ 188 m)",
      "Full (Trg @ 238 m)",
      "Full (Trg @ 288 m)",
      "Full (Trg @ 338 m)",
      "Full model",
      "Target only",
      "Target @ 138 m",
      "Target @ 188 m",
      "Target @ 238 m",
      "Target @ 288 m",
      "Target @ 338 m",
      "Target @ ???",
      "West dyke only"};

Then we can define a legend like so ...

ltxt = titl[[cmp[[#]]]] & /@ Range[Length@cmp];
llin = Graphics[{col[[#]], Thickness[.1], Line[{{-1, 0}, {0, 0}}]}] & /@
Range[Length@cmp];
lgnd = {Transpose[{llin, ltxt}],
    LegendShadow -> None,
    LegendPosition -> {.3, .05},
    LegendSize -> {.7, .5}
    };

After scaling our data, we can use the legend as below ...

tmp = aztrg[[cmp[[#]]]] & /@ Range[Length@cmp];
plt = MultipleListPlot[Log[10, tmp[[#]]], PlotStyle -> {
    ccol[[#]]}] & /@ Range[Length@cmp];

plta = Show[plt, PlotLabel -> "Model comparison over orebody"];
pltb = ShowLegend[plta, lgnd];

Where aztrg are the actual data, in this case, a {time, response} pair.

Regards,

Dave. 



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 19/01/2005


  • Prev by Date: Re: Algebraic problem solved by simulation
  • Next by Date: Re: Algebraic problem solved by simulation
  • Previous by thread: Re: ShowLegend....
  • Next by thread: Algebraic problem solved by simulation