# PlotLegends question

Two lists:

line = {{0, 2.15}, {0.05, 2.03}, {0.1, 1.94}, {0.2, 1.8}, {0.3,
1.68}, {0.4, 1.58}};
points = {{0.1009, 1.206}, {0.19455, 1.4569}, {0.3597, 1.2315}};


I'd like to plot the line with the points, and have a legend.

ListPlot[{line, points}, PlotRange -> {0, 2.5}, PlotLegends -> {"line", "points"}, PlotMarkers -> {" ", \[FilledSquare]}, Joined -> {True, False}]


Why doesn't PlotLegends pick up the line? Any way around this, other than manually?

• Confused about what? I don't want markers on the first one. I want a line. I want the legend to exactly mirror what ListPlot is doing. Jul 21, 2014 at 21:35

This works automatically in Mathematica 10. Using your original input:

line = {{0, 2.15}, {0.05, 2.03}, {0.1, 1.94}, {0.2, 1.8}, {0.3,
1.68}, {0.4, 1.58}};
points = {{0.1009, 1.206}, {0.19455, 1.4569}, {0.3597, 1.2315}};

ListPlot[{line, points}, PlotRange -> {0, 2.5},
PlotLegends -> {"line", "points"},
PlotMarkers -> {" ", \[FilledSquare]}, Joined -> {True, False}]


• (+1) Looking forward to trying it, especially to see legending and general scientific plotting. I'm especially curious whether tick marks can be customized more easily (perhaps with themes, or at least in interactive post-processing). That's just one of my eternal unresolved complaints.
– Jens
Jul 9, 2014 at 19:17
• You beat me to it. (+1) Jul 9, 2014 at 19:20
• So, yes. It wasn't functioning properly in 9. Thanks. Time to upgrade. Jul 21, 2014 at 21:39
line = {{0, 2.15}, {0.05, 2.03}, {0.1, 1.94}, {0.2, 1.8}, {0.3,
1.68}, {0.4, 1.58}};
points = {{0.1009, 1.206}, {0.19455, 1.4569}, {0.3597, 1.2315}};


With markers on line

ListPlot[{line, points},
PlotRange -> {0, 2.5},
PlotLegends -> {"line", "points"},
PlotMarkers -> {{■, 12}, {●, 12}},
Joined -> {True, False}]


Without markers on line

Show[
ListLinePlot[line,
PlotLegends -> {"line"},
PlotStyle -> Blue],
ListPlot[points,
PlotLegends -> {"points"},
PlotMarkers -> {{●, 12}},
PlotStyle -> Red],
PlotRange -> {0, 2.5},
AxesOrigin -> {0, 0}
]


• (+1) Strange that the legend for the plot with a line and marker contains only the marker and not the line, isn't it? But you do get both in the second example using ListLinePlot if PlotMarkers is added there...
– Jens
Jul 1, 2014 at 19:11
• Klunky, but it works. Thanks. Jul 21, 2014 at 21:36

It doesn't pick up the line 'cause you telling not to do ...

PlotMarkers -> {" ", ■}


with the " " you just typeset an emty space. Try

ListPlot[{line, points}, PlotRange -> {0, 2.5},
PlotLegends -> {"line", "points"},
PlotMarkers -> {●, ■},
Joined -> {True, False}]


check this.

• I don't want the markers. Just the line. Even with your solution, there is no line in the legend. Just the marker.. Jul 21, 2014 at 21:38

I get the same result as Brett Champion in version 11.3.0.0 given your code. However, I encountered a similar problem when using LogPlot, which also uses the PlotLegends option in Version 11.3.0.0.

For the function:

labeledbifurcagtingrootedtrees[x_] := Module[{m}, m = x; (Factorial[((2*m)-3)])/((2^(m-2))*Factorial[m-2])]


and its plot:

p1 = LogPlot[labeledbifurcagtingrootedtrees[n], {n, 3, 14}, PlotStyle->Blue, PlotLegends->"Labeled Unrooted Trees"]


Note that the PlotLegend is missing.

However, simply by putting the string in a list, the problem goes away:

p1 = LogPlot[labeledbifurcagtingrootedtrees[n], {n, 3, 14}, PlotStyle->Blue, PlotLegends->{"Labeled Unrooted Trees"}]


This is something not expected from the Documentation for PlotLegends.