Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: A nice and customized legend within Manipulate
Replies: 1   Last Post: Nov 5, 2012 6:40 PM

 Messages: [ Previous | Next ]
 Alexei Boulbitch Posts: 483 Registered: 2/28/08
Re: A nice and customized legend within Manipulate
Posted: Nov 5, 2012 6:40 PM

Hello

I need to create a cdf document as a standalone file that can be used in
a computer without Mathematica. There is quite a few plots in the doc
and I need to add nice legends to it. At first I tried the Legend
package but I found the result awful and worse than that it breaks the
standalone cdf (something to do with Needs and Get or the like).

It seems that I need to add a initialization code within Manipulate but
I have no idea on how to do it. Could someone help me with an example,

Finally, is there a simple way to create nice legends? I saw several
posts on the web but could not gather much from them. A nice and simple
example (for a newbie) will help me a lot.

Many thanks

Ed

Hi, Ed,

Try this:

Plot[{x, x^2}, {x, -10, 10}, PlotRange -> All,
PlotStyle -> {Blue, Red},

(* Here the legend starts*)
Epilog ->
Inset[Grid[{{Graphics[{Blue, Line[{{0, 0}, {1, 0}}]},
ImageSize -> {20, 20}],
Style["First line",
14]}, {Graphics[{Red, Line[{{0, 0}, {1, 0}}]},
ImageSize -> {20, 20}], Style["Second line", 14]}},
Alignment -> {Left, Center}, Spacings -> 0], {5, 80}]
(* The end of the legend *)
]

and this:

(* These are two lists to plot *)
lst1 = Table[{x, x}, {x, -10, 10, 0.5}];
lst2 = Table[{x, x^2}, {x, -10, 10, 0.5}];
(* End of lists definition *)

ListPlot[{lst1, lst2}, PlotRange -> All, PlotStyle -> {Blue, Red},

(* Here the legend starts*)
Epilog ->
Inset[Panel[
Grid[{{Graphics[{Blue, Point[{0, 0}]}, ImageSize -> {20, 20}],
Style["First list", 14]}, {Graphics[{Red, Point[{0, 0}]},
ImageSize -> {20, 20}], Style["Second list", 14]}},
Alignment -> {Left, Center}, Spacings -> 0],
ImageSize -> {105, 80}], {4, 85}]
(* The end of the legend *)
]

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu

Date Subject Author
11/4/12 Eduardo Mendes
11/5/12 Alexei Boulbitch