RE: Problems using Legend whith LogPlot and LogPlotPlot

• To: mathgroup at smc.vnet.net
• Subject: [mg36844] RE: [mg36827] Problems using Legend whith LogPlot and LogPlotPlot
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 29 Sep 2002 02:55:02 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Awk! Legends!

Basically, the answer to your question is that the PlotLegend option works
ONLY for the Plot command and does not work for other types of plots. For
other types of plots you have to use ShowLegend. And ShowLegend is not all
that easy to use, especially since WRI does not give an example for multiple
curves in the Help.

Needs["Graphics`Graphics`"]
Needs["Graphics`Legend`"]
{q1[t_], q2[t_], q3[t_]} = {0.1 Exp[-0.02 t], 0.2 Exp[-0.025 t],
0.4 Exp[-0.028 t]};

Let's look at your first plot.

Plot[{q1[t], q2[t], q3[t]}, {t, 0, 100},
PlotStyle -> {{AbsoluteThickness[0.5], AbsoluteDashing[{4, 4}]},
AbsoluteThickness[1.5], {AbsoluteThickness[2],
AbsoluteDashing[{1, 8}]}},
AxesLabel -> {"Y", "X"},
PlotLabel -> "Title",
PlotLegend -> {"1", "3", "5"},
LegendPosition -> {0.5, 0},
ImageSize -> 500];

The legend is almost as big as the plot. It distracts from the real
information you are trying to convey. Furthermore, the order of the curves
in the legend is the reverse of their order in the plot.

The following shows how to put the legend in a LogLogPlot, or other types of
plots. I defined the plot styles independently because they are used in
several places. I made the legend much smaller and put it in an empty area
of the plot. I also reversed the order of the keys so they would match the
order of the curves in the plot.

styles={{AbsoluteThickness[0.5],
AbsoluteDashing[{4,4}]},{AbsoluteThickness[1.5]},{AbsoluteThickness[
2],AbsoluteDashing[{1,8}]}};

ShowLegend[
LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100}, PlotStyle -> styles,
AxesLabel -> {"Y", "X"},
PlotLabel -> "Title",
ImageSize -> 500,
DisplayFunction -> Identity],
Line[{{0, 0}, {1, 0}}]}], #2} &, {styles, {1, 3, 5}}] //
Reverse,
LegendPosition -> {-0.7, -0.4},
LegendSize -> {0.2, 0.3},
LegendSpacing -> 0.5}
];

But why use a legend at all? After all, a legend is nothing but another plot
in which you have put labels on the curves. Why not put the labels directly
on the curves in the real plot in the first place?

LogLogPlot[{q1[t], q2[t], q3[t]}, {t, 0, 100},
PlotStyle -> styles,
AxesLabel -> {"Y", "X"},
PlotLabel -> "Title",
ImageSize -> 500,
Epilog ->
Text[SequenceForm["Case ", #1], {Log[10, 0.01],
Log[10, #2[0.01]]}, {0, -1}] &, {{1, 2, 3}, {q1, q2, q3}}]];

In the legend you have keyed the curves to numbers 1, 3 and 5. (Perhaps you
just used these as examples and meant to use something different in the real
plots?) But these don't seem to have any obvious relation to your functions.
I suppose the reader will have to look at another table or look into the
text of your paper or notebook to find out what 1, 3 and 5 mean. So the
reader has to go from the graph to the legend then to the text and then
mentally transfer the meaning of the curve back to the main plot. It is so
much nicer to put the meaning right on the curve if you can.

For the most part, legends are just "computer junk" and not even easy to
nicely construct. When the legend urge comes over you - try to resist.

David Park

From: guillerm at usal.es [mailto:guillerm at usal.es]
To: mathgroup at smc.vnet.net

Dear friends

I have the following problem with Legend and LogPlot and LogPlotPlot:

Needs["Graphics`Graphics`"]

Needs["Graphics`Legend`"]

{q1[t_],q2[t_],q3[t_]}={0.1 Exp[-0.02 t], 0.2 Exp[-0.025 t],
0.4 Exp[-0.028 t]};

(*With Plot legend works fine*)

Plot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle\[Rule]{
{AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]},
AbsoluteThickness[1.5], {AbsoluteThickness[2],
AbsoluteDashing[{1,8}]}}, AxesLabel\[Rule]{"Y", "X"},
PlotLabel\[Rule]"Title", PlotLegend\[Rule]{"1","3","5"},
LegendPosition\[Rule] {0.5,0}]

(*However with LogPlot or LogLogPlot the legend desappear*)

LogLogPlot[{q1[t],q2[t],q3[t]}, {t, 0, 100},PlotStyle\[Rule]{
{AbsoluteThickness[0.5], AbsoluteDashing[{4,4}]},
AbsoluteThickness[1.5], {AbsoluteThickness[2],
AbsoluteDashing[{1,8}]}}, AxesLabel\[Rule]{"Y", "X"},
PlotLabel\[Rule]"Title", PlotLegend\[Rule]{"1","3","5"},
LegendPosition\[Rule] {0.5,0}]

I have shown a particular case, but I has this problem always with Legend
and
LogPlot and LogPlotPlot. I will appreciate any help.
Thanks
Guillermo
Sanchez

---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/

```

• Prev by Date: Re: Bug in Solve?
• Next by Date: Colored ListPlot
• Previous by thread: Problems using Legend whith LogPlot and LogPlotPlot
• Next by thread: Bug in Solve?