MathGroup Archive 2011

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

Search the Archive

Re: legend in a combined plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123779] Re: legend in a combined plot
  • From: JUN <noeckel at gmail.com>
  • Date: Mon, 19 Dec 2011 07:15:55 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jckcbk$1m0$1@smc.vnet.net>

On Dec 18, 1:39 am, Nike Dattani <dattani.n... at gmail.com> wrote:
> Greetings!
> I'd love to be able to make a legend for the following figure:
> =========================
> {aa, a} = Timing[Plot[x^2, {x, 0, 1}, PlotRange -> {0, 1}, PlotStyle -> {{Thickness[0.025], Black}}]];
>
> {cc, c} = Timing[Plot[x^2, {x, 0, 1}, PlotRange -> {0, 1}, PlotStyle -> {Thickness[0.01], Red, Dashed}]];
>
> {bb, b} = Timing[Plot[x^2, {x, 0, 1}, PlotRange -> {0, 1}, Mesh -> 15,
> MeshStyle -> Directive[PointSize[0.035], Green], PlotStyle ->
> {{Thickness[0.01], Red, Dashed}}]];
>
> Show[a, c, b]
> =========================
> with the first curve being "CPU time =" aa
>
> I've tried using:
> Needs["PlotLegends`"]
>
> along with Show[a,c,b,PlotLegend->{{"CPU time=" aa},{"CPU time=" cc},
> {"CPU time=" bb}}
>
> And I've also tried putting the legend command inside the Plot command
> in the line {aa,a}=Timing[Plot.....
>
> But sadly, neither of these methods worked ='(
>
> Would any brave souls wish to lead me to the light ?
> Thank you!
> Nike

Hi,
the PlotLegends package is quite useless for what you're trying to do
(one reason being the MeshStyle trick you're using). Instead, you
could try to work with the suggestion I posted here:
http://groups.google.com/group/comp.soft-sys.math.mathematica/msg/d8573f45fda9f956

In your case, I would use the legendMaker function defined there as
follows:

With[{adjustedThickness = .05, diskRadius = .01},
 Overlay[{Show[a, c, b],
   legendMaker[{Directive[Thickness[adjustedThickness*2.5], Black],
     Directive[Thickness[adjustedThickness], Red, Dashed],
     Directive[Thickness[adjustedThickness], Red]}, {"", "",
     Graphics[{Green, Disk[{0, 0}, diskRadius]}, ImageSize -> 10]},
    Map[Row[{"CPU Time = ", #}] &, {aa, bb, cc}],
    Background -> Directive[Opacity[.5], Yellow]]},
  Alignment -> {-.5, .9}]]

As you can see, it requires some manual adjustments of the line
thickness and the disk radius because the overlay doesn't know how to
scale itself relative to the graphic it's superimposed on. I also had
to translate the line styles of your plots to the form of a
Directive.

The use of dashing and thickness in your example plot could probably
be improved, but at least this will hopefully answer your question
about how to get a legend appropriate for a plot with a highly
customized appearance: The answer is unfortunately not to be found in
Mathematica's built-in legends tool set.

Jens



  • Prev by Date: Re: How to define a localized indexed object in Manipulate?
  • Next by Date: How to not show the scrollbars when ContentSize does not fit the content in Manipulate?
  • Previous by thread: legend in a combined plot
  • Next by thread: How to define a localized indexed object in Manipulate?