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


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

legend in a combined plot

Started byNike Dattani <dattani.nike@gmail.com>
First post2011-12-18 09:39 +0000
Last post2011-12-19 12:16 +0000
Articles 2 — 2 participants

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


Contents

  legend in a combined plot Nike Dattani <dattani.nike@gmail.com> - 2011-12-18 09:39 +0000
    Re: legend in a combined plot JUN <noeckel@gmail.com> - 2011-12-19 12:16 +0000

#7329 — legend in a combined plot

FromNike Dattani <dattani.nike@gmail.com>
Date2011-12-18 09:39 +0000
Subjectlegend in a combined plot
Message-ID<jckcbk$1m0$1@smc.vnet.net>
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









[toc] | [next] | [standalone]


#7336

FromJUN <noeckel@gmail.com>
Date2011-12-19 12:16 +0000
Message-ID<jcn9vj$e2v$1@smc.vnet.net>
In reply to#7329
On Dec 18, 1:39 am, Nike Dattani <dattani.n...@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

[toc] | [prev] | [standalone]


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


csiph-web