Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm new to this site and new to Mathematica as you can see from my question. I'm also new to programming, btw.

I'm trying to produce a legend for my plot which I've coded as follows:

Needs["PlotLegends`"]
ds1 = {{0, 0.53}, {10, 1.00}, {20, 2.19}, {35, 3.61}};
ds2 = {{0, 0.52}, {10, 0.91}, {20, 1.97}, {35, 3.09}};
ds3 = {{0, ds1[[1, 2]] - ds2[[1, 2]]}, 
       {10, ds1[[2, 2]] - ds2[[2, 2]]}, 
       {20, ds1[[3, 2]] - ds2[[3, 2]]}, 
       {35, ds1[[4, 2]] - ds2[[4, 2]]}
      };
mf1 = LinearModelFit[ds1, x, x];
mf2 = LinearModelFit[ds2, x, x];
mf3 = LinearModelFit[ds3, x, x];
m1 = mf1["BestFit"]; m2 = mf2["BestFit"]; m3 = mf3["BestFit"];

Show[
  {
    ListPlot[{ds1, ds2, ds3}, 
       PlotMarkers -> Automatic, PlotStyle -> {Blue, Red, Orange}
    ], 
    Plot[{m1, m2, m3}, {x, 0, 35}, PlotStyle -> {Blue, Red, Orange}]
  }, 
  Frame -> True, 
  FrameLabel -> {"Time (min)","Inorganic Phosphate Concentration (mM)"},
  ImageSize -> {400, 300}
]

So, I'd like to use the ShowLegend function to have the legend displayed outside of the frame. I know that I can use the LegendPosition function to do this.

My problem, however, is the tags. How do I get the legend to show the names of the plots (ds1, ds2, ds3, m1, m2, and m3)?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Something like this?

ShowLegend[
 Show[{ListPlot[{ds1, ds2, ds3}, PlotMarkers -> Automatic, 
    PlotStyle -> {Blue, Red, Orange}], 
   Plot[{m1, m2, m3}, {x, 0, 35}, PlotStyle -> {Blue, Red, Orange}]}, 
  Frame -> True, 
  FrameLabel -> {"Time (min)", 
    "Inorganic Phosphate Concentration (mM)"}, ImageSize -> {500}],
 {{
   {Style["\[FilledCircle]", 12, Blue], "ds1"},
   {Style["\[FilledSquare]", 12, Red], "ds2"},
   {Style["\[FilledDiamond]", 12, Orange], "ds3"},
   {Graphics@{Blue, Line[{{0, 0}, {1, 0}}]}, "m1"},
   {Graphics@{Red, Line[{{0, 0}, {1, 0}}]}, "m2"},
   {Graphics@{Orange, Line[{{0, 0}, {1, 0}}]}, "m3"}
   }, LegendPosition -> {1, -0.4}}
 ]

Mathematica graphics

share|improve this answer
    
Thank you very much for you answer. It was what I was looking for. –  WalidSaladin Sep 10 '12 at 6:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.