Re: PlotLegend and Show
- To: mathgroup at smc.vnet.net
- Subject: [mg117950] Re: PlotLegend and Show
- From: David Annetts <david.annetts at iinet.net.au>
- Date: Tue, 5 Apr 2011 06:44:40 -0400 (EDT)
Hi Robert,
My advice with this package would be to ignore it.
IMHO, you're better off constructing a legend by hand using Epilog. An
example is given below.
(* construct plot styles, then 10 Sin curves which we'll plot as one *)
pcol = Hue[#] & /@ (1/11. Range[10]);
psty = Directive[Thick, #] & /@ pcol;
p = Plot[1/# Sin[# x], {x, 0, 2 \[Pi]},
PlotStyle -> psty[[#]],
FrameTicks -> {{Automatic, None}, {{0, \[Pi], 2 \[Pi]}, None}},
PlotRange -> {Automatic, {-1.1, 1.1}}] & /@ Range[1, 10];
Show[p]
(* this is essentially what you want, but without a legend. Let's
define one programatically *)
ltxt = Text[
Style[ToString[#], Smaller, Background->White,
FontColor -> pcol[[#]]], {1.925 \[Pi], 1 - .1 #}, {-1, 0}] & /@
Range@Length@pcol;
ltxt = Join[ltxt, {Text["\[Times] \[Pi]", {1.9 \[Pi], 1}, {-1, 0}]}];
(* we use it thusly *)
Show[p, Epilog -> {ltxt}]
YMMV.
D.
On 4/04/2011 18:30, Robert McHugh wrote:
> Have made a plot which uses PlotLegend. Would like to combine this plot
> with another plot. Tried using Show[] to do this, but the results were not
> not what I expected. In the combined plot, the second plot doesn't have the
> same scale as the first plot. When I remove the PlotLegend option from the
> first plot and use show to combine the two plots all is well. Below is an
> example. (Though in the case I would like to run, there are about 10
> different graphs in the first plot, so making the legend by hand would be
> time consuming.)
>
> Recommendations? Thanks.
>
> (* this isn't what I want *)
> p1 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotLegend -> {"sine", "cosine"}]
> p2 = Plot[{Sin[x + \[Pi]], Cos[x + \[Pi]]}, {x, 0, 2 Pi}]
> Show[p1, p2]
>
> (* remove the legend and all is well *)
> p1 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi} ]
> p2 = Plot[{Sin[x + \[Pi]], Cos[x + \[Pi]]}, {x, 0, 2 Pi}]
> Show[p1, p2]