8
$\begingroup$

I am drawing a plot with some legends. It seems the legend markers will always have lines through them since I have to use Joined->True for this plot. The legend markers also seem to be always larger than those in the plot. My question is, is it possible to get rid of those lines through the legend markers and also make the legend markers smaller? Besides, is there a way to remove the grey outlines around the legend markers?

enter image description here

The code I used for this plot is

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[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]
$\endgroup$
7
$\begingroup$

Just add the options Joined -> False and BaseStyle -> EdgeForm[] to PointLegend in your code to get

enter image description here

If you don't like the red syntax highlighting of BaseStyle -> EdgeForm[] you can use Method -> { BaseStyle -> EdgeForm[]}.

$\endgroup$
4
$\begingroup$

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]}}]]

enter image description here

$\endgroup$
4
$\begingroup$

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}}]

enter image description here

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]

enter image description here

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]

enter image description here

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

$\endgroup$
2
$\begingroup$

This is just an answer for your last question. You can get rid of the border of your markers in the legend by specifying EdgeForm[None], e.g.:

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@{EdgeForm[None],Disk[]},0.04},
        {Graphics@{EdgeForm[None],Rectangle[]},0.04}
    },
    InterpolationOrder->1,
    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
]

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.