Re: listplot and legend (again)
- To: mathgroup at smc.vnet.net
- Subject: [mg80842] Re: listplot and legend (again)
- From: John Jowett <John.M.Jowett at gmail.com>
- Date: Tue, 4 Sep 2007 03:40:11 -0400 (EDT)
- References: <200708090918.FAA21022@smc.vnet.net>
Hello,
I think it may be useful to give another scheme that will cover
some common cases and, I think, fill a hole in the present
documentation for Mathematica 6. I would say it is complementary to
Thomas Muench's. I base the example on one an earlier thread between
Robert Pigeon and "dh" in May this year.
Needs["PlotLegends`"]
(* Define two lists of points *)
data1 = Table[{x, Sin[x]}, {x, 1, 5}];
data2 = Table[{x, x^Sin[x]}, {x, 1, 5}];
(* Define the style and labels for them *)
style12 = {
{{Red, Thick, Line[{{0.05, .7}, {0.25, .7}}]}, "Sin[x]"},
{{Blue, Thick, Line[{{0.05, .7}, {0.25, .7}}]}, "x^Sin[x]"}
};
(* Make the plot without the legend *)
plot12 = ListLinePlot[{data1, data2}, PlotStyle -> First /@ style12]
(* Include the legend, choose its position, etc. *)
ShowLegend[plot12, {style12, LegendPosition -> {.2, .3},
LegendSize -> {.62, .3}}]
I find it helpful to group the style definitions and captions in the
list style12 at the beginning.
John Jowett
On Aug 22, 10:48 am, "Muench, Thomas" <thomas.mue... at fmi.ch> wrote:
> Hello, Arek
>
> When Mathematica automatically chooses colors for plotting inListPLot
> or ListLinePlot, it takes colors defined in ColorData[1], in the order
> defined there. That means, your first line (or set of points) is plotted
> in ColorData[1,1], the second in ColorData[1,2], and so on. I don't
> think that this is mentioned anywhere in the Help system.
>
> Once you know this, it is straight foreward to make your own legends,
> with not need for the PlotLegend package.
>
> Here are two examples; the first one plots thelegendas part of the
> Plot itself (as Epilog), the second shows thelegendas a separate
> element next to the Plot.
>
> data = Table[RandomReal[], {4}, {5}];
>
> legend= Framed@
> Column[Table[
> Style["data " <> ToString[i], ColorData[1, i], Bold, "Graphics",
> 15], {i, Length[data]}]];
>
> (* Example 1 *)
> ListLinePlot[data, ImageSize -> 300,
> Epilog -> Inset[legend, {.5, .5}]]
>
> (* Example 2 *)
> Row[{ListLinePlot[data, ImageSize -> 300],legend}]
>
> Hope that helps,
> Thomas
>
> On 8/14/07, Arkadiusz.Ma... at gmail.com <Arkadiusz.Ma... at gmail.com> wrote:
>
> Hi,
>
> I know that there has been at least one post on this topic but I still
> can't drawlegendinsideListPlot.
>
> When i plot several curves, colors for them are chosen automaticaly
> by Mathematica. How can I plot alegendfor them?
>
> May I ask for an example, please? Why quite good solution existed in
> MultipleListPlot in Mathv5.2 just vanished????
>
> Arek