Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem for using "Epilog" to plot legend

410 views
Skip to first unread message

davis

unread,
Apr 11, 2008, 1:46:06 AM4/11/08
to
Dear Group

i want to use "Epilog" to plot a legend,but i have a problem for the "Line" command.

ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
Epilog ->
Inset[Framed@
Column[{Graphics[{DotDashed, Line[{{1, 0}, {2, 0}}]}] Style["a"],
Graphics[{Dotted, Line[{{1, 0}, {2, 0}}]}] Style["b"]},
Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]]

the space between different rows in "legend area" are really large,

but if i change the Line condition,such like below

ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
Epilog ->
Inset[Framed@
Column[{Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}]
Style["a"],
Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] Style["b"]},
Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]]

the rows became close to each other, but the length of the lines became too long

how can i solve this?

thank you

Albert Retey

unread,
Apr 11, 2008, 5:58:52 AM4/11/08
to

I found Grid to be more fitted for these things, because you can take
much more control about all the details like item sizes. Using
Dividers->All also gives you an idea what the sizes and margins really
are. This should be a reasonable starting point for fine tuning:

ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,

Epilog -> Inset[Framed@Grid[{{
Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}] , Style["a"]
}, {
Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] , Style["b"]
}},
ItemSize -> {{5, 2}, 0.5},
Dividers -> None
],
{1.25, 7}]
]

hth,

albert

Bill Rowe

unread,
Apr 12, 2008, 7:10:56 AM4/12/08
to
On 4/11/08 at 1:43 AM, davis...@gmail.com (davis) wrote:

>i want to use "Epilog" to plot a legend,but i have a problem for the
>"Line" command.

>ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
>PlotMarkers -> Automatic, Epilog -> Inset[Framed@
>Column[{Graphics[{DotDashed, Line[{{1, 0}, {2, 0}}]}] Style["a"],
>Graphics[{Dotted, Line[{{1, 0}, {2, 0}}]}] Style["b"]}, Spacings ->
>0, ItemSize -> {15, 0.5}], {1.25, 7}]]

>the space between different rows in "legend area" are really large,

>but if i change the Line condition,such like below

>ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
>PlotMarkers -> Automatic, Epilog -> Inset[Framed@
>Column[{Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}] Style["a"],
>Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] Style["b"]}, Spacings
>-> 0, ItemSize -> {15, 0.5}], {1.25, 7}]]

>the rows became close to each other, but the length of the lines
>became too long

>how can i solve this?

My approach would be to use Text instead of Style and specify
placement of all of the elements rather than use Column to line
things up. For example,

ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
Epilog ->
Inset[Framed@

Graphics[{DotDashed, Line[{{5, 0}, {2, 0}}],
Text["a", {5.1, 0}, {1, 0}], Dotted,
Line[{{5, -.5}, {2, -.5}}],
Text["b", {5.1, -.5}, {1, 0}]}], {1.5, 7}, {0, 0}, 1.5]]

David Park

unread,
Apr 12, 2008, 7:13:38 AM4/12/08
to
I didn't quite see what the legend had to do with the plot. But in any case,
with Presentations it is convenient to simply draw the legend lines on the
plot as additional elements.

Needs["Presentations`Master`"]

Draw2D[
{ListDraw[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
PlotStyle -> {Black, Darker@Red}],
(* Draw legend *)
Black, Line[Scaled /@ {{.1, .8}, {.3, .8}}],
Text["a", Scaled[{.35, .8}]],
Darker@Red, Line[Scaled /@ {{.1, .7}, {.3, .7}}],
Text["b", Scaled[{.35, .7}]]},

AspectRatio -> 1/GoldenRatio,
Axes -> True,
PlotRange -> {{0, 5.1}, {0, 10}},
BaseStyle -> {FontSize -> 12}]

Or, in this case, it might be more direct to simply label the two curves.
Version 6.0.2 has a graphics tool for picking off coordinates (but it gives
you an extra set of brackets that must be edited out) and Presentations has
a LocatorDraw feature that gives you a temporary Locator and display for
picking off coordinates.

Draw2D[
{ListDraw[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
PlotStyle -> {Black, Darker@Red}],
(* Label Curves *)
Text[Style["a", 16], {4.26069, 6.55068}],
Text[Style["b", 16], {3.14569, 7.37447}]},

AspectRatio -> 1/GoldenRatio,
Axes -> True,
PlotRange -> {{0, 5.1}, {0, 10}},
BaseStyle -> {FontSize -> 12},
ImageSize -> 350]

--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


"davis" <davis...@gmail.com> wrote in message
news:ftmtuu$4ob$1...@smc.vnet.net...

nano...@gmail.com

unread,
May 27, 2008, 7:16:32 AM5/27/08
to
On 11 Apr, 00:46, davis <davis.v....@gmail.com> wrote:
> Dear Group
>
> i want to use "Epilog" to plot alegend,but i have a problem for the "Line" command.

>
> ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
> PlotMarkers -> Automatic,
> Epilog ->
> Inset[Framed@
> Column[{Graphics[{DotDashed, Line[{{1, 0}, {2, 0}}]}] Style["a"],
> Graphics[{Dotted, Line[{{1, 0}, {2, 0}}]}] Style["b"]},
> Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]]
>
> the space between different rows in "legendarea" are really large,

>
> but if i change the Line condition,such like below
>
> ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
> PlotMarkers -> Automatic,
> Epilog ->
> Inset[Framed@
> Column[{Graphics[{DotDashed, Line[{{100, 0}, {2, 0}}]}]
> Style["a"],
> Graphics[{Dotted, Line[{{100, 0}, {2, 0}}]}] Style["b"]},
> Spacings -> 0, ItemSize -> {15, 0.5}], {1.25, 7}]]
>
> the rows became close to each other, but the length of the lines became too long
>
> how can i solve this?
>
> thank you
Adjust a little bit, and it works.

ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}}, Joined -> True,
PlotMarkers -> Automatic,
Epilog ->
Inset[Framed@

Graphics[{{DotDashed, Line[{{1, 0}, {2, 0}}]},
Text[Style["a", Bold, 8], {2.5, 0}], {Dotted,
Line[{{1, -1}, {2, -1}}]},
Text[Style["b", Bold, 8], {2.5, -1}]}, ImageSize -> 40,
AspectRatio -> 0.4], {1.25, 7}]]

0 new messages