8
$\begingroup$

I am using Mathematica 9. The problem I have is with plotlengends, in particular,

g2 = ListPlot[{{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}}, 
  PlotStyle -> {Dashing[Large]}, PlotLegends -> {"Dashed"}, 
  Joined -> True];
g1 = ListPlot[{{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}, {4.5, 6.6}, {5, 
    7}, {6, 9}, {8, 11}}, Joined -> True, PlotStyle -> {Dotted}, 
  PlotLegends -> {"Dot"}];
Show[g1, g2]

enter image description here

As you can see, the problem is that looking at this lengends, there is no way you can tell which curve coresponds to which one in the legends (for instance, is the dash curve coresponds to the top legend or the bottom legend?). Changing the color will not work because this plot has to be in black and white only. Please help.

$\endgroup$
  • $\begingroup$ Works perfectly with me: "10.0 for Microsoft Windows (64-bit) (June 29, 2014)" $\endgroup$ – eldo Aug 31 '14 at 17:15
  • $\begingroup$ Sorry, it is matehamtica 9 $\endgroup$ – kuku Aug 31 '14 at 17:15
9
$\begingroup$

As noted by Eldo, this works out of the box on Mathematica 10. On Mathematica 9 LineLegend does the trick:

data2 = {{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}};
data1 = {{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}, {4.5, 6.6}, {5, 7}, {6, 9}, {8, 11}};

ListPlot[
 {data1, data2}, 
 Joined -> True, 
 PlotStyle -> {Dotted, Dashing[Large]}, 
 PlotLegends -> LineLegend[{Dotted, Dashing[Large]}, {"Dot", "Dashed"}]
]

Mathematica graphics

$\endgroup$
2
$\begingroup$

This works with both versions:

g2 = ListPlot[{{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}}, 
   PlotStyle -> {Dashing[Large]}, Joined -> True];

g1 = ListPlot[{{2, 1}, {3, 4}, {3.5, 4.2}, {4, 6}, {4.5, 6.6}, {5, 
     7}, {6, 9}, {8, 11}}, Joined -> True, PlotStyle -> {Dotted}];

Legended[Show[g1, g2], 
 LineLegend[{Dashed, Dotted}, {"Dashed", "Dot"}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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