Re: ShowLegend....
- To: mathgroup at smc.vnet.net
- Subject: [mg53633] Re: [mg53617] ShowLegend....
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 21 Jan 2005 06:35:39 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Peter, Generally I dislike Legend, both because it is complicated to manipulate and because it is just another plot that distracts the viewer from the message of the main graphic. If the curves aren't too crowded it is better to label the two curves directly. Otherwise it is possible to draw the legend directly on the plot. I would do this with the DrawGraphics package from my web site below. Here is an example of directly labeling two curves. Needs["DrawGraphics`DrawingMaster`"] Draw2D[ {(* Draw and label Sin curve *) Draw[Sin[x], {x, 0, 2Pi}], Text[Sin[x], {2.5, Sin[2.5]}, {-1.2, 0}], (* Draw and label Cos curve *) AbsoluteDashing[{3}], Draw[Cos[x], {x, 0, 2Pi}], Text[Cos[x], {1.5, Cos[1.5]}, {1.2, 0}]}, Frame -> True, Background -> Linen, PlotLabel -> "Labeling Two Curves", ImageSize -> 450]; Here is an example of drawing the legends directly on the plot. Draw2D[ {(* Draw and make legend for x^2 curve *) Draw[x^2, {x, 0, 1}], Draw[0.95, {x, 0.05, 0.2}], Text[x^2, {0.25, 0.95}], (* Draw and make legend for x^3 curve *) AbsoluteDashing[{3}], Draw[x^3, {x, 0, 1}], Draw[0.87, {x, 0.05, 0.2}], Text[x^3, {0.25, 0.87}]}, Frame -> True, Background -> Linen, PlotLabel -> "Making a Legend for Two Curves", ImageSize -> 450]; With DrawGraphics you can easily combine as many different lines, curves and graphics directives as you wish in a single drawing statement. It's a natural way to do it. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: plizak [mailto:plizak at gmail.com] To: mathgroup at smc.vnet.net There has to be an easier way to do this.... I was trying to figure out how to use showlegend, and here's what I came out with.... (* plot2 and plot3 are two different plots *) plotX = Show[ {plot2 , plot3}, PlotRange -> {{ -0.4, 0.4}, {-1, 10}}] legend = ShadowBox[ {-0.4, 6}, {0.3, 3}, ShadowBackground -> GrayLevel[ 0.5], ShadowOffset -> {0.025, -0.5}]; showlegend = Show[ plotX, Graphics[{legend , { Text["Normal - solid", {-.375, 6.775}, {-1.0, 0}], Text["Data - dashed", {-.375, 7.775}, {-1.0, 0}] } } ] ] That is way to much code to just add a legend to a graph. Is there a faster/easier way to do this? Is there a way that the legend also includes an example of the line / linestyle? Cheers and thanks, Peter