Re: Fixing the legend
- To: mathgroup at smc.vnet.net
- Subject: [mg39149] Re: Fixing the legend
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 31 Jan 2003 04:37:16 -0500 (EST)
- References: <b18498$kq2$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Sergio, 1. To get the text inside the legend box you need to be sure that the box will be wide enough to fit it, for example by setting the using the option ImageSize or by dragging the box (once you have chosen the font size the size of the text is fixed and does not alter when the size of the display is altered). 2. To miss out some of the symbols it seems necessary to use the more general way of making legends using the template ShowLegend[graphics objects, {legendspecification}...,opts] Needs["Graphics`Colors`"]; Needs["Graphics`Legend`"]; Make a graphics object gr = Plot[{E^x, x^x, x!}, {x, 0, 3}, AspectRatio -> 1/2, PlotStyle -> {{Dashing[{.02, .04}], Hue[0]}, Hue[.35], Hue[.7]}, Frame -> True, FrameTicks -> False, FrameStyle -> {Thickness[.01], Red}]; and a helper surface=Plot3D[2Sin[x y],{x,0,3},{y,0,3},Boxed->False,Axes->False, Mesh->False]; Define two legend specifications - these are for illustration -they are not related to the contents of gr. legspec1=Sequence[{{Hue[0],"red"},{Graphics[{Hue[0],Line[{{0,0},{1,0}}]}], "red"},{Hue[.8],"purple"},{surface,"surface"}}, LegendShadow->{0,0},LegendSpacing->0]; legspec2=Sequence[Hue[.7#]&,5,"min","max"]; -use them to add two legends to gr. -notice the blue frame is for the whole display ShowLegend[ gr,{legspec1,LegendPosition->1,-1/2}},{legspec2, LegendPosition->{1,0}},Frame->True,FrameTicks->False, FrameStyle->{Thickness[.01],Blue}]; -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Sergio Rojas" <sergio_r at mail.com> wrote in message news:b18498$kq2$1 at smc.vnet.net... > Hello folks, > > How can one make the symbols labeling in the legend > of the following plot to fix inside the surrounding > box? Would it be possible to turn off the symbols > labeling for the 3rd. and 4th. lines, where no > legend is assigned? > > > (*-------------------------------------------------------------------------- *) > Needs["Graphics`MultipleListPlot`"]; > Needs["Graphics`Legend`"]; > > Clear[getPlotInfo]; > getPlotInfo[data_,x_] := > Module[{l2Norm, l2NormToPlot, maxNorm, maxNormToPlot, h , hMin, hMax, > yl2, l2NormFitedData}, > l2NormToPlot = Table[{ h[i]=data[[i]][[2]], l2Norm[i]=data[[i]][[3]]}, > {i,1,Length[data]}]; > maxNormToPlot = Table[{ data[[i]][[2]], maxNorm[i]=data[[i]][[4]]}, > {i,1,Length[data]}]; > h = Log[Table[h[i],{i,1,Length[data]}]]; > hMin = Min[h]; > hMax = Max[h]; > l2Norm = Table[l2Norm[i],{i,1,Length[data]}]; > maxNorm = Table[maxNorm[i],{i,1,Length[data]}]; > yl2[x1_] := Evaluate[Fit[Log[l2NormToPlot], {1,x1}, x1]]; > l2NormFitedData = Table[{i,yl2[i]},{i,hMin,hMax,(hMax-hMin)/20}]; > Return[{Log[l2NormToPlot], l2NormFitedData, yl2[x] }]]; > > dataM1 = > {{5., 0.25, 0.00217807, 0.00325421}, {10., 0.111111, 0.00042537099999999996, > 0.000712573}, {20., 0.0526316, 0.0000934578, 0.000167083}, > {40., 0.025640999999999997, 0.000021898399999999997, 0.0000404748}, > {80., 0.0126582, 5.300360000000001*^-6, 9.961790000000001*^-6}}; > > dataM2 = > {{5., 0.25, 0.00880884, 0.010398000000000001}, > {10., 0.111111, 0.00190426, 0.00209391}, {20., 0.0526316, 0.000442025, > 0.000473797}, {40., 0.025640999999999997, 0.00010649599999999999, > 0.00011289800000000002}, {80., 0.0126582, 0.0000261382, 0.000027567}}; > > Clear[M1LogPlotData, M1FitData, Mi2aFit, leg1, y]; > {M1LogPlotData, M1FitData, Mi2aFit} = getPlotInfo[dataM1, y]; > leg1=StringJoin["Methods 2-2-2 fit: ", > ToString[StringForm["`1`",Mi2aFit /. y -> Ln[x]]]] > > Clear[M2LogPlotData, M2FitData, MiSOFit, leg2, y]; > {M2LogPlotData, M2FitData, MiSOFit} = getPlotInfo[dataM2, y]; > leg2=StringJoin["Methods 1-2-1 fit: ", > ToString[StringForm["`1`",MiSOFit /. y -> Ln[x]]]] > > Clear[sym1,sym2]; > sym1 = PlotSymbol[Box,2] > sym2 = PlotSymbol[Star,4] > > Clear[thePlot]; > thePlot := > MultipleListPlot[M1LogPlotData, > M1FitData, > M2LogPlotData, > M2FitData, > PlotJoined -> {False, True, False, True}, > SymbolShape -> {sym1, None, sym2, None}, > Axes -> False, > Frame -> True, > FrameLabel -> {"Ln(x)", "Ln(y)", > "Fitting Test", > "Test 1"}, > PlotLegend -> {leg1, > "", > leg2, > "" > }, > LegendSize -> {1.5, .3}, > (* > LegendBorder -> 0, > LegendLabelSpace->.5, > LegendTextOffset -> {{-1,0},{-1,0},{-1,0},{-1,0}}, > LegendTextOffset -> {3,0}, > *) > LegendPosition -> {-.8, -1} > ]; > Show[thePlot] > > > Sergio >