# LineLegend behaves differently in ListPlot in Mathematica Version10.0 or later

Suppose I want a line legend for a list plot:

dat = RandomReal[{.8, 1.2}, 40]*Range@40;

ListPlot[Transpose@{Range@40, dat},
PlotLegends ->
Placed[LineLegend[{Style["I want a line legend!!!",
18]}], {.4, .8}]]


However, the output doesn't show a line legend but something that looks like a point legend:

I use Mathematica 10.0.2 on Windows 7. Is this a bug?

• Mma 10 -- there are a few sub-versions, please, add the necessary version info. – Sektor Jul 31 '15 at 13:45
• To check version, use Help -> About in the GUI or use both $Version and $ReleaseNumber. Unfortunately $Version and $VersionNumber will not contain the z part of an x.y.z form version number. – Szabolcs Jul 31 '15 at 14:23
• @Szabolcs how did you know that my $ReleaseNumber gives 2? By GUI->About It's 10.0.2 indeed! – Harry Jul 31 '15 at 14:30 • @Harry I have 10.0.2 installed and the date of December 4, 2014 (in $Version) matches with yours. If yours showed an earlier date, I couldn't tell if it was 10.0.0 or 10.0.1 as I don't have those versions any more. – Szabolcs Jul 31 '15 at 14:34

## 2 Answers

This is not a bug. I think that this is not a bug, see addendum.

Based on my (limited!) experience, I believe that LineLegend and PointLegend are in fact the very same thing with differing default options. LineLegend has Joined -> True while PointLegend has Joined -> False by default, but otherwise they are identical.

The syntax you used, i.e. LineLegend[{"label1", "label2", ...}] causes the legend to inherit the style from the plot, which means Joined -> False. You can fix this by specifying the option manually.

LineLegend[{Style["I want a line legend!!!", 18]}, Joined -> True]


If you use PointLegend instead, it will do the same thing. The only important factor is the values of the Joined option.

If you use these legends outside of the PlotLegends option of some type of plot, they will not inherit any options and will behave as their name would suggest (and as determined by their default options).

### Addendum

Harry points out that in version 9 these legends do not inherit the Joined option from the parent plot, thus LineLegend always gives a line and PointLegend always gives a point.

Should we consider this behaviour change a breakage in v10? I don't think so because the v9 behaviour also causes problems. In v9, ListPlot[Transpose@{Range@40, dat}, PlotLegends -> {"label"}, Joined -> True] uses a point legend, even though the plot has a line. This seems to have been fixed in v10 by causing the legend to inherit the Joined option from the parent.

• seems it's a new feature of version10(version 9 behaves differently). It's quite reasonable after all. – Harry Jul 31 '15 at 14:25
• @Harry You're right, see update. – Szabolcs Jul 31 '15 at 14:33
\$Version


"10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)"

dat = Transpose@{Range@40, RandomReal[{.8, 1.2}, 40]*Range@40};

Legended[
ListPlot[dat],
Placed[
LineLegend[{Blue},
{Style["I want a line legend!!!", 14]}],
{.3, .8}]]