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


Groups > comp.soft-sys.math.mathematica > #1456 > unrolled thread

PlotLegend and Show

Started byRobert McHugh <r62m10@gmail.com>
First post2011-04-04 10:30 +0000
Last post2011-04-05 10:41 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  PlotLegend and Show Robert McHugh <r62m10@gmail.com> - 2011-04-04 10:30 +0000
    Re: PlotLegend and Show Chris Degnen <degnen@cwgsy.net> - 2011-04-05 10:41 +0000

#1456 — PlotLegend and Show

FromRobert McHugh <r62m10@gmail.com>
Date2011-04-04 10:30 +0000
SubjectPlotLegend and Show
Message-ID<inc6k2$tb$1@smc.vnet.net>
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]

[toc] | [next] | [standalone]


#1472

FromChris Degnen <degnen@cwgsy.net>
Date2011-04-05 10:41 +0000
Message-ID<inerkq$j41$1@smc.vnet.net>
In reply to#1456
On Apr 4, 11:30 am, Robert McHugh <r62...@gmail.com> 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]


PlotLegend is a Plot option only, so you need to use ShowLegend:

Needs["PlotLegends`"]
p1 = Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}]
p2 = Plot[{Sin[x + \[Pi]], Cos[x + \[Pi]]}, {x, 0, 2 Pi}]
ShowLegend[
 Show[p1, p2], {{{Graphics[{Hue[0.67, 0.6, 0.6],
      Line[{{0, 0}, {1, 0}}]}],
    "sine"}, {Graphics[{Hue[0.9, 0.6, 0.6], Line[{{0, 0}, {1, 0}}]}],
    "cosine"}}}]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web