Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1482

Re: PlotLegend and Show

From Heike Gramberg <heike.gramberg@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: PlotLegend and Show
Date 2011-04-05 10:43 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <inerof$j7h$1@smc.vnet.net> (permalink)

Show all headers | View raw


You could do something like

Needs["PlotLegends`"];
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}];
p3 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}];
legend = Release[
   Hold[p1[[##]]] & @@ Position[p1, _GraphicsGroup][[1]]];
Graphics[{Inset[Show[p3, p2], {0, 0}, Center, 2], legend},
 PlotRange -> {{-1.2, 1}, {-1, 1}}]

Maybe it's not a very nice solution, but at least it's less work than building a
legend by hand.

Heike.

On 4 Apr 2011, at 12: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]

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: PlotLegend and Show Heike Gramberg <heike.gramberg@gmail.com> - 2011-04-05 10:43 +0000

csiph-web