Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Legends for Plot's (solution)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102414] Re: Legends for Plot's (solution)
  • From: Ben Shepherd <bjashepherd at mailinator.com>
  • Date: Sat, 8 Aug 2009 04:39:51 -0400 (EDT)
  • References: <h5bk30$hja$1@smc.vnet.net>

I rewrote the LineStylesFromTooltips function to work with unjoined
ListPlots as well, where just points are displayed:

LineStylesFromTooltips[plot_Graphics] :=
  Cases[plot,
   Tooltip[{s__, l_Point | l_Line}, tt_] :> Grid[{{Switch[Head@l,
        Point,
        Graphics[Flatten[{s, Point@{0, 0}}], ImageSize -> {4, 8},
         AspectRatio -> 8/4, ImagePadding -> 0],
        Line,
        Graphics[Flatten[{s, Line[{{0, 0}, {1, 0}}]}],
         ImageSize -> {24, 8}, AspectRatio -> 8/24,
         ImagePadding -> 0]], tt}}], Infinity];

Thanks very much for this - it looks loads better than the default
PlotLegend!

ben
(to reply directly, mailinator -> gmail)

On 5 Aug, 10:40, dr DanW <dmaxwar... at gmail.com> wrote:
> The PlotLegends` package is badly dated and creates unattractive
> legends.  InMathematica7, there is support for very attractive
> legends, but only for the new Chart types.  The mechanism is a little
> different than in PlotLegends.  Legends are implemented by placing the
> wrapper Legended[] around the data being plotted.  The chart function
> knows to ignore Legended[] except when looking forlegendtext.
>
> On the other hand, Plot[] knows nothing about Legended[], and will not
> recognize anything in that wrapper as data.  Plot[] does recognize the
> Tooltip[] wrapper, however.
>
> Below is code that will create an attractivelegendout of any
> Tooltip'ed curve in a Plot.  This will only work on lines, not
> markers, so if you use it on ListPlot, make sure Joined->True.  The
> main function is LineLegendFromTooltips[].
>
> Usage example:
> LineLegendFromTooltips[ Plot[{Tooltip[x,"x"], Tooltip[x^2,"x^2"]},{x,
> 0,3} ] ]
>
> -------code------------
> LineStylesFromTooltips[plot_Graphics] :=
>     Cases[plot, Tooltip[{s__, l_Line}, tt_] :>
>         Grid[{{Graphics[Flatten[{s, Line[{{0, 0}, {1, 0}}]}],
>                 ImageSize -> {24, 8}, AspectRatio -> 8/24=
,
>         ImagePadding -> 0],
>               tt}}], Infinity]
>
> LineLegendFromTooltips[plot_Graphics] :=
>     Labeled[plot, Style[Column[LineStylesFromTooltips[plot]], "TR",
>         ShowStringCharacters -> False], Right]
>
> -----end code-------
>
> I sincerely hope this function will be unnecessary in version 8.0.
>
> Daniel



  • Prev by Date: Re: Why use OptionsPattern, OptionsValue ?
  • Next by Date: Re: error with Sum and Infinity
  • Previous by thread: Legends for Plot's (solution)
  • Next by thread: Finding positive / non-complex solutions (newbie)