How to remove lines through the legend markers in ListPlot?
Just add the options Joined -> False
and BaseStyle -> EdgeForm[]
to PointLegend
in your code to get
If you don't like the red syntax highlighting of BaseStyle -> EdgeForm[]
you can use Method -> { BaseStyle -> EdgeForm[]}
.
Here is a work around.
Show[ListPlot[{{1, 2, 3, 4, 5}, (1/2) {1, 2, 3, 4, 5}},
PlotStyle -> {Blue, Red},
PlotMarkers -> {{Graphics@{EdgeForm[None], Disk[]},
0.04}, {Graphics@{EdgeForm[None], Rectangle[]}, 0.04}},
Frame -> {{True, False}, {True, False}},
PlotLegends ->
Placed[
PointLegend[
Automatic, {Style["Series 1", FontFamily -> "Times New Roman",
FontSize -> 9, ScriptMinSize -> 6],
Style["Series 2", FontFamily -> "Times New Roman",
FontSize -> 9, ScriptMinSize -> 6]}], {0.3, 0.8}],
ImageSize -> 240],
ListLinePlot[{{1, 2, 3, 4, 5}, (1/2) {1, 2, 3, 4, 5}},
PlotStyle -> {{Blue, Dashed, AbsoluteThickness[1]}, {Red, Dashed,
AbsoluteThickness[1]}}]]
Define a standalone legend
:
legend = PointLegend[{Blue, Red},
{Style["Series 1", FontFamily -> "Times New Roman", FontSize -> 9, ScriptMinSize -> 6],
Style["Series 2", FontFamily -> "Times New Roman", FontSize -> 9, ScriptMinSize -> 6]},
LegendMarkers -> {{Graphics@{EdgeForm[None], Disk[]}, 0.04},
{Graphics@{EdgeForm[None], Rectangle[]}, 0.04}}]
Unfortunately, simply adding PlotLegends -> Placed[legend, {0.3, 0.8}]
doesn't work:
ListPlot[{{1, 2, 3, 4, 5}, (1/2) {1, 2, 3, 4, 5}},
Joined -> True,
PlotStyle -> {{Blue, Dashed, AbsoluteThickness[1]}, {Red, Dashed,
AbsoluteThickness[1]}},
PlotMarkers -> {{Graphics@{Disk[]}, 0.04}, {Graphics@{Rectangle[]},
0.04}}, InterpolationOrder -> 1,
Frame -> {{True, False}, {True, False}},
PlotLegends -> Placed[legend, {0.3, 0.8}],
ImageSize -> 240]
However, this approach with HoldForm
is succesful:
ListPlot[{{1, 2, 3, 4, 5}, (1/2) {1, 2, 3, 4, 5}},
Joined -> True,
PlotStyle -> {{Blue, Dashed, AbsoluteThickness[1]}, {Red, Dashed,
AbsoluteThickness[1]}},
PlotMarkers -> {{Graphics@{Disk[]}, 0.04}, {Graphics@{Rectangle[]},
0.04}}, InterpolationOrder -> 1,
Frame -> {{True, False}, {True, False}},
PlotLegends -> Placed[HoldForm@Evaluate@legend, {0.3, 0.8}],
ImageSize -> 240]
Alternatively, Legended
is a workaround:
Legended[
ListPlot[{{1, 2, 3, 4, 5}, (1/2) {1, 2, 3, 4, 5}}, Joined -> True,
PlotStyle -> {{Blue, Dashed, AbsoluteThickness[1]}, {Red, Dashed,
AbsoluteThickness[1]}},
PlotMarkers -> {{Graphics@{Disk[]}, 0.04}, {Graphics@{Rectangle[]},
0.04}}, InterpolationOrder -> 1,
Frame -> {{True, False}, {True, False}}, ImageSize -> 240],
Placed[legend, {0.3, 0.8}]]
same plot as above