# Using PlotLegends

Please don't answer this with "Just trash PlotLegends" or anything like that as I have tried homebrew solutions. I keep running into problems which I can't debug as I'm not super familiar with Mathematica.

However, to my question: If I have a ListPlot with say 6 lists, I can use PlotLegends -> {x_1, x_2, x_3, x_4, x_5, x_6} to label each individual one as x_1, ..., x_6. However, x_1 and x_2 (though different plots) correspond to the same data set (in the experiment I'm doing) and I have them labeled with alternating filled and empty markers (filled triangle/open triangle) and the same color.

So what I want is

x_1, x_2 with filled/empty triangle and line all colored blue
x_3, x_4 with filled/empty square and line all colored red
x_5, x_6 with filled/empty diamond and line all colored green

That is

-ftri-etri- (in blue) Set 1
-fsq-esq- (in red) Set 2
-fdi-edi- (in green) Set 3

Is there a way to make a legend that has a line with the filled AND empty marker on it, which I can label TOGETHER giving only 3 entries in the legend? If that makes sense?

Sorry if that's confusing.

• Could you please post a minimal working example so people can try your code and see what is wrong. Mar 14, 2013 at 22:49

There is absolutely nothing to stop you setting your legend up this way using a custom plot marker in a SwatchLegend. For example, consider some data:

fakedata =
Table[FoldList[0.99 #1 + #2 &, 0.,
RandomVariate[NormalDistribution[0, 1], {99}]], {6}];


Create a custom marker:

blob = Graphics[{AbsoluteThickness[1.4], Line[{{-0.5, 0}, {0.5, 0}}],
Text["\[FilledCircle]", {-0.25, 0}],
Text["\[EmptyCircle]", {0.25, 0}]}, AspectRatio -> 0.2]


Here is a graph with six series, organised into pairs with the same color but different plot markers, and a legend with only three elements, using the custom legend element defined above.

ListLinePlot[fakedata, PlotStyle -> {Orange, Blue, Green},
PlotMarkers -> {"\[FilledCircle]", "\[FilledCircle]",
"\[FilledCircle]", "\[EmptyCircle]", "\[EmptyCircle]",
"\[EmptyCircle]"},
PlotLegends ->
Placed[SwatchLegend[{"type 1", "type 2", "type 3"},
LegendMarkers -> blob, LegendMarkerSize -> 20], Bottom]]


Notice that the colors of the lines are automatically picked up without having to be specified explicitly.

By the way, the negative feelings about Mathematica legends largely related to versions before 9. I find the new legending functionaly in version 9 to be quite effective.

A little deviation from Verbeia's answer because I don't like the offset of the symbols (e.g. \[FilledCircle]) as PlotMarkers. I am using Disk and Circle primitives instead.

mydisk[col_] := Graphics[{col, Disk[{0, 0}, 1]}];
mycirc[col_] := Graphics[{col, Circle[{0, 0}, 1]}];

ListLinePlot[fakedata, PlotStyle -> {Orange, Blue, Green},
PlotMarkers -> {{mydisk[Orange], 0.04}, {mydisk[Blue], 0.04}, {mydisk[Green], 0.04},
{mycirc[Orange], 0.04}, {mycirc[Blue], 0.04}, {mycirc[Green], 0.04}},
PlotLegends -> Placed[SwatchLegend[{"type 1", "type 2", "type 3"},
LegendMarkers -> blob, LegendMarkerSize -> 20], Bottom]]


Here is a demonstration (thanks to Verbeia), using the PlotLegends functionality current in Mma 7.

fakedata = Table[FoldList[0.99 #1 + #2 &, 0.,
RandomReal[NormalDistribution[0, 1], 99]], {6}];

blob = Graphics[{AbsoluteThickness[1.4],
Style[Line[{{-0.5, 0}, {0.5, 0}}], Antialiasing -> False],
Text["\[FilledCircle]", {-0.25, 0}],
Text["\[EmptyCircle]", {0.25, 0}]}, AspectRatio -> 0.2];

<< PlotLegends

ShowLegend[ListLinePlot[fakedata, PlotStyle -> {Orange, Blue, Green},
PlotMarkers -> {"\[FilledCircle]", "\[FilledCircle]",
"\[FilledCircle]", "\[EmptyCircle]", "\[EmptyCircle]",
"\[EmptyCircle]"}],
{{{Insert[blob, Orange, {1, 1}], Style["type 1", 12]},
{Insert[blob, Blue, {1, 1}], Style["type 2", 12]},
{Insert[blob, Green, {1, 1}], Style["type 3", 12]}},
LegendPosition -> {-0.7, 0.25}, LegendSize -> {0.5, 0.3},
LegendTextSpace -> 1, LegendShadow -> False}]
`