RE: Problem with the legend in MultipleListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg41487] RE: [mg41473] Problem with the legend in MultipleListPlot
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 22 May 2003 06:54:42 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Marcus, I always find MultipleListPlot and Legend a pain in the neck. It is really an art to get the spacing and everything correct in a legend box. Furthermore, legends are not usually a good graphical device. They take up a lot of space and convey only a little information. Usually I would simply label the two curves using Text statements, putting the labels next to each curve. This is the most direct way for a viewer to "read" the information from the graphic. The viewer does not have to keep transferring from the curve to the legend. So here is a way to do that without MultipleListPlot of Legend. (I have changed your plot somewhat in that I used a smaller plot range. The difference in the data barely shows in the larger plot range. I also used a larger font because I couldn't even read it on the screen. Perhaps this all changes your intention so just take it as an example that we can work with on screen.) Here is just labeling the curves... help1 = Transpose[{Range[50, 150, 10], {1.2, 2.3, 2.3, 4.0, 5.1, 5.2, 5.9, 6.4, 7.1, 8.5, 10.1}}]; help2 = Transpose[{Range[50, 150, 10], {1.4, 2.3, 3.3, 4.0, 5.5, 6.2, 6.9, 6.4, 6.1, 7.5, 9.2}}]; xgrid = Table[{x, {GrayLevel[0.8]}}, {x, 60, 140, 10}]; ygrid = Table[{x, {GrayLevel[0.8]}}, {x, 0, 10, 2}]; Show[Graphics[ {(* Draw initial data and label *) Thickness[0.003], Dashing[{0.01}], Line[help1], Text[ StyleForm["Initial", FontSize -> 11], {100.178, 4.92904}, {-1, 0}, Background -> White], (* Draw 3 month data and label *) Dashing[{}], Line[help2], Text[ StyleForm["3 Months", FontSize -> 11], {99.4393, 6.48189}, {1, 0}, Background -> White]}, Frame -> True, PlotRange -> {{50 - 0.0001, 150}, {0, 10}}, GridLines -> {xgrid, ygrid}, PlotLabel -> "Net Present Value of Project", FrameLabel -> {"Cash Flow in $", "$"}, ImageSize -> 500]]; However, since in your case the curves are so close, it might not be possible to distinguish them well enough with direct labeling. In that case, you can make you own legend, with far easier control, this way... Show[Graphics[ {(* Draw initial data and legend *) Thickness[0.003], Dashing[{0.01}], Line[help1], Line[{Scaled[{0.1, 0.92}], Scaled[{0.2, 0.92}]}], Text[StyleForm["Initial", FontSize -> 11], Scaled[{0.21, 0.92}], {-1, 0}, Background -> White], (* Draw 3 month data and legend *) Dashing[{}], Line[help2], Line[{Scaled[{0.1, 0.87}], Scaled[{0.2, 0.87}]}], Text[StyleForm["3 Months After Initiation", FontSize -> 11], Scaled[{0.21, 0.87}], {-1, 0}, Background -> White]}, Frame -> True, PlotRange -> {{50 - 0.0001, 150}, {0, 10}}, GridLines -> {xgrid, ygrid}, PlotLabel -> "Net Present Value of Project", FrameLabel -> {"Cash Flow in $", "$"}, ImageSize -> 500]]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Marcus Schulmerich [mailto:mschulme at yahoo.com] To: mathgroup at smc.vnet.net Hi, I have a question related to MultiplListPlot with a legend in the diagram. The text files data_1.dat, data_2.dat contain the data in the table-format: For file data_1.dat: 50 1.2 60 2.3 70 2.3 80 4.0 90 5.1 100 5.2 110 5.9 120 6.4 130 7.1 140 8.5 150 10.1 For file data_2.dat: 50 1.4 60 2.3 70 3.3 80 4.0 90 5.5 100 6.2 110 6.9 120 6.4 130 6.1 140 7.5 150 9.2 To load the data: help1 = Import["data_1.dat", "table"] help2 = Import["data_2.dat", "table"] Use: <<Graphics`MultipleListPlot` Mathematica command: MultipleListPlot[help1, help2, PlotJoined -> True, Frame -> True, PlotRange -> {{49.9999, 150.0001}, {-75.0001, 100.0001}}, GridLines -> {Table[{x, {GrayLevel[0.8]}}, {x, 60, 140, 10}], Table[{x, {GrayLevel[0.8]}}, {x, -50, 75, 25}]}, TextStyle -> {FontSize -> 7, FontFamily -> "Times New Roman"}, PlotLegend -> {StyleForm["initial", FontSize -> 6, FontFamily -> "Times New Roman"], StyleForm["after 3 mos after initiation.", FontSize -> 6, FontFamily -> "Times New Roman"]}, LegendPosition -> {-0.45, 0.25}, LegendSize -> {0.8, 0.2}, FrameLabel -> {"Cash inflows in $", "Net present value of project in $"}, SymbolShape -> {None, None}, Axes -> False , PlotStyle -> {{Thickness[0.003], GrayLevel[0.0]}, {Dashing[{0.01}], Thickness[0.003], GrayLevel[0.2]}}, ImageSize -> 300]; The legend is pretty long to get the text in the box. But when prolonging the box the length of the small sample graph in the box does not get longer and there is lots of free space in the box. Is there way to make the two lines in the box longer somehow?? Thanks, Marcus __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com