Prev: Map vs. Table
Next: How to add legend to ListLinePlot?
From: Robert Pigeon on 12 May 2007 03:10 Hello, I want to create a Legend on a ListLinePlot I made. I have 4 data groups I plot on one graph and I want to identify each one by its colour and a name. I read about the Legend Package, but it seems, if I understand correctly, to work only with Plot like graphs. I do not understand why it is so difficult (it seems to me anyway) to add a legend to a graph. It is common practice in science to identify a plot with a legend, so others can understand your graphics. With the Plot command it seems straight forward to do this with PlotLegend (mind you I do not see how I can move the legend around...). Why this package is not available with all other graphics tools, like ListPlot, ListLinePlot,.... Or maybe it is just me ... J Thanks, Robert Robert Pigeon
From: David Annetts on 14 May 2007 03:27 Hi Robert, > I want to create a Legend on a ListLinePlot I made. I have > 4 data groups I plot on one graph and I want to identify each > one by its colour and a name. > > I read about the Legend Package, but it seems, if I > understand correctly, to work only with Plot like graphs. I > do not understand why it is so difficult (it seems to me > anyway) to add a legend to a graph. It is common practice in > science to identify a plot with a legend, so others can > understand your graphics. With the Plot command it seems > straight forward to do this with PlotLegend (mind you I do > not see how I can move the legend around...). Why this > package is not available with all other graphics tools, like > ListPlot, ListLinePlot,.... > > > > Or maybe it is just me ... J It might just be you ....:) For 5.2 and earlier, Legends can be moved using the directive LegendPosition->{x, y}. For other plotting commands, Legends can be used with the command ShowLegend. It's tedious, but not particularly difficult. I hope that Legend use with 6.0 is much less tedious. Anyway, given data = Random[] & /@ Range[32]; p1 = ListPlot[data]; We can define a line using lin = {Graphics[Line[{{-1, 0}, {0, 0}}]]}; And a legend using lgd = {Transpose[{lin, {"Legend"}}], LegendLabel -> StyleForm["Label", FontWeight -> "Bold"], LegendOrientation -> Vertical, LegendSize -> {.4, .2}, LegendShadow -> .01, LegendPosition -> {-.2, -.95} }; We use them together with ShowLegend[] as ShowLegend[p1, lgd]; The tedium comes when trying to position the legend, but the two positions below should get you started. LegendPosition -> {-.8, .35} (* top left *) LegendPosition -> {.5, -.5} (* bottom right *) For graphs of more than one data set, you'll need muliple Legend entries, for example, given data = {Random[], Random[]} & /@ Range[32]; data = Transpose[data]; p1 = MultipleListPlot[data, PlotStyle -> {Red, Blue}, SymbolShape -> None]; One Legend might be lin = Graphics[{#, Line[{{-1, 0}, {0, 0}}]}] & /@ {Red, Blue}; lgd = {Transpose[{lin, {"Curve 1", "Curve 2"}}], LegendLabel -> StyleForm["Comparison", FontWeight -> "Bold"], LegendOrientation -> Vertical, LegendSize -> {.4, .2}, LegendShadow -> .01, LegendPosition -> {.5, -.5} }; ShowLegend[p1, lgd]; Regards, Dave.
From: Robert Pigeon on 14 May 2007 03:43 Hi David, Thanks for the reply! And, yes, it might be just me... :) But my question was with Mathematica 6.0 .... Your examples are not working in ver. 6.0 because the Legend package was changed. They do work with 5.2. I was using Dave Park's DrawGraphics package for my graphics and legends, but now the package is not working properly anymore. So my question is still open :) How can we add legends to a plot (ListPlot or ListLinePlot) to identify curves ? Robert Robert Pigeon -----Original Message----- From: David Annetts [mailto:davidannetts(a)aapt.net.au] Sent: May-13-07 08:35 To: 'Robert Pigeon'; mathgroup(a)smc.vnet.net Subject: RE: Mathematica 6.0 - Legend Hi Robert, > I want to create a Legend on a ListLinePlot I made. I have > 4 data groups I plot on one graph and I want to identify each > one by its colour and a name. > > I read about the Legend Package, but it seems, if I > understand correctly, to work only with Plot like graphs. I > do not understand why it is so difficult (it seems to me > anyway) to add a legend to a graph. It is common practice in > science to identify a plot with a legend, so others can > understand your graphics. With the Plot command it seems > straight forward to do this with PlotLegend (mind you I do > not see how I can move the legend around...). Why this > package is not available with all other graphics tools, like > ListPlot, ListLinePlot,.... > > > > Or maybe it is just me ... J It might just be you ....:) For 5.2 and earlier, Legends can be moved using the directive LegendPosition->{x, y}. For other plotting commands, Legends can be used with the command ShowLegend. It's tedious, but not particularly difficult. I hope that Legend use with 6.0 is much less tedious. Anyway, given data = Random[] & /@ Range[32]; p1 = ListPlot[data]; We can define a line using lin = {Graphics[Line[{{-1, 0}, {0, 0}}]]}; And a legend using lgd = {Transpose[{lin, {"Legend"}}], LegendLabel -> StyleForm["Label", FontWeight -> "Bold"], LegendOrientation -> Vertical, LegendSize -> {.4, .2}, LegendShadow -> .01, LegendPosition -> {-.2, -.95} }; We use them together with ShowLegend[] as ShowLegend[p1, lgd]; The tedium comes when trying to position the legend, but the two positions below should get you started. LegendPosition -> {-.8, .35} (* top left *) LegendPosition -> {.5, -.5} (* bottom right *) For graphs of more than one data set, you'll need muliple Legend entries, for example, given data = {Random[], Random[]} & /@ Range[32]; data = Transpose[data]; p1 = MultipleListPlot[data, PlotStyle -> {Red, Blue}, SymbolShape -> None]; One Legend might be lin = Graphics[{#, Line[{{-1, 0}, {0, 0}}]}] & /@ {Red, Blue}; lgd = {Transpose[{lin, {"Curve 1", "Curve 2"}}], LegendLabel -> StyleForm["Comparison", FontWeight -> "Bold"], LegendOrientation -> Vertical, LegendSize -> {.4, .2}, LegendShadow -> .01, LegendPosition -> {.5, -.5} }; ShowLegend[p1, lgd]; Regards, Dave.
From: dh on 14 May 2007 05:48 Hi Robert, look up "ShowLegend" in the manual. This works for any type of graphics. hope this helps, Daniel Robert Pigeon wrote: > Hello, > > I want to create a Legend on a ListLinePlot I made. I have 4 data groups > I plot on one graph and I want to identify each one by its colour and a > name. > > I read about the Legend Package, but it seems, if I understand correctly, > to work only with Plot like graphs. I do not understand why it is so > difficult (it seems to me anyway) to add a legend to a graph. It is common > practice in science to identify a plot with a legend, so others can > understand your graphics. With the Plot command it seems straight forward to > do this with PlotLegend (mind you I do not see how I can move the legend > around...). Why this package is not available with all other graphics tools, > like ListPlot, ListLinePlot,.... > > > > Or maybe it is just me ... J > > > > Thanks, > > > > Robert > > > > Robert Pigeon >
From: dh on 16 May 2007 06:02 Hello Robert, I do not blame you having problems, the documentation for ShowLegend is really horrible. Here is an example, assuming your graphics with 2 curves is in g: ShowLegend[g,{{{Red,"asas"},{Blue,"qwqw"}},LegendPosition->{1,0} }] hope this helps, Daniel Robert Pigeon wrote: > Needs["PlotLegends`"] >a = Table[{i,i^2},{i,1,20}]; >b = Table[{i,i^3},{i,1,20}]; >ListLinePlot[a, PlotStyle -> {Red}] > >(* I get a nice graph of my data *) > >(* Here I would like to put a Legend showing the color and name of the plot *) > >ShowLegend[ > ListLinePlot[a, PlotStyle->{Red}], > Legend[{Red,"Line a"}] >] <And it does NOT work.... I get the following as output > > > > Robert > > > > Robert Pigeon >
|
Pages: 1 Prev: Map vs. Table Next: How to add legend to ListLinePlot? |