Re: Q: Problems with package legend.m
- To: mathgroup at smc.vnet.net
- Subject: [mg3449] Re: Q: Problems with package legend.m
- From: ianc (Ian Collier)
- Date: Fri, 8 Mar 1996 01:30:38 -0500
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
In article <4hm0es$m6m at dragonfly.wolfram.com>, "Alexander K White"
<whiteale at pilot.msu.edu> wrote:
> Hello,
> I am using Mathematica 2.2 for NeXT and I am having problems with the
> package Legend.m which is included in the graphics package.
> I created a plot, pl2, which contains the graphs of two functions on the same
> plot. When I use
> In [] = ShowLegend[pl2,{{RGBColor[0, 1, 1],
>
> "LTBD"},{RGBColor[1,0,1],"hiho"}}]
>
> I get the error
>
> Out[]= Graphics::gprim:
> Unknown Graphics primitive Legend[{RGBColor[0, 1, 1], LTBD}, <<2>>]
> encountered.
>
> I looked inside the function ShowLegend and it calls another function Legend.
> When I use
>
> In[] := Show at Graphics@Legend[{{RGBColor[0, 1, 1],
>
> "LTBD"},{RGBColor[1,0,1],"hiho"}}]
>
> Out[]= picture of the legend.
>
> It seems that the ShowLegend calls Legend incorrectly. Has anyone else
> experienced this? This seems to be a major bug.
>
> I changed a few lines in ShowLegend from:
> ls = MapAt[Append[#,LegendPosition->ap]&,ls,1];
> ls = Apply[Legend,ls,{1}];
> to:
> ls = Append[ls,LegendPosition->ap];
> ls = Legend@(Sequence@@ls);
>
> And it appears to work. I wonder if I am not using the function correctly, or
> if there are other bugs in the package.
>
> If this topic has been covered before, I apologize. Please send an address
> where I can receive information.
>
You just need to add a another set of braces around the legend
specification.
The reason is that ShowLegend accepts multiple legend specifications,
each of which has its own options; the extra set of braces is used
to group the options with each specification.
In[1]:=
pl2 = Plot[ {Sin[x]/x, Cos[x]},{x,-10,10}]
Out[1]=
-Graphics-
In[2]:=
Needs[ "Graphics`Legend`" ]
In[3]:=
ShowLegend[pl2,{{{RGBColor[0, 1, 1],
"LTBD"},{RGBColor[1,0,1],"hiho"}}}]
Out[3]=
-Graphics-
Once you have loaded the Legend package you can also simply
use PlotLegend as an option to Plot:
In[4]:=
Plot[{Sin[x]/x, Cos[x]}, {x, -10,10},
PlotLegend -> {"LTBD", "hiho"},
PlotStyle -> {RGBColor[0,1,1], RGBColor[1,0,1]}]
Out[4]=
-Graphics-
The place where you can receive information about this
and other technical questions about Mathematica and
the standard Mathematica packages is Wolfram Research
Technical Support (support at wolfram.com).
I hope this helps.
--Ian
-----------------------------------------------------------
Ian Collier
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217) 398-0700 fax:(217) 398-0747 ianc at wolfram.com
Wolfram Research Home Page: http://www.wolfram.com/
-----------------------------------------------------------
==== [MESSAGE SEPARATOR] ====