From: Ramiro on
Any suggestions on how to add a legend in an ErrorBarPlot?

The simple PlotLegend option that used to work on ListPlot doesn't
work here.

Needs["ErrorBarPlots`"];
Needs["PlotLegends`"];
ListPlot[{Table[i, {i, 10}], Table[i + 3, {i, 10}]}, Joined -> True,
PlotLegend -> {"A", "B"}]
ErrorListPlot[{Table[{i, RandomReal[0.5]}, {i, 10}],
Table[{i + 3, RandomReal[0.5]}, {i, 10}]}, Joined -> True,
PlotLegend -> {"A", "B"}]

From: dh on
Hi Ramiro
ErrorListPlot does not have the option "PlotLegend". This is certainly
not a nice feature, but we may use the more complicated "ShowLegend"
instead. Here is an example:

Needs["ErrorBarPlots`"];
Needs["PlotLegends`"]; ShowLegend[
ErrorListPlot[{Table[{i, RandomReal[0.5]}, {i, 10}],
Table[{i + 3, RandomReal[0.5]}, {i, 10}]},
Joined ->
True], {{{Graphics[{Red, Disk[{0, 0}, 1]}],
"A"}, {Graphics[{Blue, Disk[{0, 0}, 1]}], "B"}},
LegendPosition -> {1, -.5}, LegendSize -> .5}]

Daniel


On 22.02.2010 09:06, Ramiro wrote:
> Any suggestions on how to add a legend in an ErrorBarPlot?
>
> The simple PlotLegend option that used to work on ListPlot doesn't
> work here.
>
> Needs["ErrorBarPlots`"];
> Needs["PlotLegends`"];
> ListPlot[{Table[i, {i, 10}], Table[i + 3, {i, 10}]}, Joined -> True,
> PlotLegend -> {"A", "B"}]
> ErrorListPlot[{Table[{i, RandomReal[0.5]}, {i, 10}],
> Table[{i + 3, RandomReal[0.5]}, {i, 10}]}, Joined -> True,
> PlotLegend -> {"A", "B"}]
>


--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh(a)metrohm.com>
Internet:<http://www.metrohm.com>


From: David Park on
With the Presentations package I would do it this way:

Needs["Presentations`Master`"]
Needs["ErrorBarPlots`"]

ShowLegend[
Draw2D[
{Black,
ErrorListPlot[Table[{i, RandomReal[0.5]}, {i, 10}],
Joined -> True] // DrawGraphics,
Red,
ErrorListPlot[Table[{i + 3, RandomReal[0.5]}, {i, 10}],
Joined -> True] // DrawGraphics},

AspectRatio -> 1/GoldenRatio,
Axes -> True,
ImageSize -> 400],

{{{Black, "A"}, {Red, "B"}},
LegendPosition -> {0.4, -0.4},
LegendSize -> {0.3, 0.2},
LegendTextOffset -> {-2, 0},
LegendSpacing -> 0.6},
BaseStyle -> {FontSize -> 12, FontWeight -> "Bold"}]

Legends are something of an old fashioned graphic technology. Their demerit
is that they present a second rather prominent graphic that competes with
the main data plot. Also, it is indirect and the eye has to go back and
forth between the legend and the plot. A better method may sometimes be to
directly label the curves with Text statements. However, a static printed
plot of many closely twining curves may require a legend.

The PlotLegends commands seem to have a logic to them but, for me at least,
they seem overly complicated. Another method is to simple draw a much
simpler, less obtrusive and more easily controlled legend directly on the
plot.

Draw2D[
{Black,
ErrorListPlot[Table[{i, RandomReal[0.5]}, {i, 10}],
Joined -> True] // DrawGraphics,
Aliasing(a)Line[{Scaled[{.8, .2}], Scaled[{.9, .2}]}],
Text["A", Scaled[{.92, .2}], {-1, 0}],
Red,
ErrorListPlot[Table[{i + 3, RandomReal[0.5]}, {i, 10}],
Joined -> True] // DrawGraphics,
Aliasing(a)Line[{Scaled[{.8, .15}], Scaled[{.9, .15}]}],
Black, Text["B", Scaled[{.92, .15}], {-1, 0}]},

AspectRatio -> 1/GoldenRatio,
Axes -> True,
ImageSize -> 400]

The aliasing was put back in so we don't get fuzzy horizontal lines.

If you can work and display entirely in an active dynamic Mathematica
notebook then there are much better solutions. First, you could use tooltips
on the curves to identify them. Another method is to use a dynamic
presentation in which one curve is shown in black or a bold color and all
the other curves are shown very faintly. The viewer could select the curve
to emphasize, say by a radio button bar. Or the display of each curve could
be controlled by a checkbox. The viewer could choose to display whatever
combination of curves he wanted to see at a time. Clicking the checkbox on
and off would help identify the curve and the curve color could be built
into the checkbox label. This way, a complex graphic can be simplified to
multiple custom plots at the viewer's discretion.

If one can manage it, dynamic graphics are far superior to static graphics.


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/



From: Ramiro [mailto:ramiro.barrantes(a)gmail.com]


Any suggestions on how to add a legend in an ErrorBarPlot?

The simple PlotLegend option that used to work on ListPlot doesn't
work here.

Needs["ErrorBarPlots`"];
Needs["PlotLegends`"];
ListPlot[{Table[i, {i, 10}], Table[i + 3, {i, 10}]}, Joined -> True,
PlotLegend -> {"A", "B"}]
ErrorListPlot[{Table[{i, RandomReal[0.5]}, {i, 10}],
Table[{i + 3, RandomReal[0.5]}, {i, 10}]}, Joined -> True,
PlotLegend -> {"A", "B"}]