4
$\begingroup$

I am plotting some data points with a legend but PlotLegend does not yield the same color as the points have. Where is the mistake?

Here is the result that I obtain: [1]: https://i.stack.imgur.com/s5yga.png

ListPlot[{{0.4, 38}, {0.5,   15}, {0.6, 10}},
 Frame -> True,
 FrameLabel -> {"a", "b"},
 PlotMarkers -> {
   Graphics[{EdgeForm[Directive[Thick, Blue]], White, Rectangle[]},ImageSize -> (15)]},
  PlotRange -> {{0.3, 0.7}, {0, 100}},
 PlotRangePadding -> {0.05, 2},
 PlotLegends -> 
  Placed[PointLegend[{"data"}, LegendMarkerSize -> 14, 
    LabelStyle -> {FontSize -> 18, FontFamily -> "Arial", 
      Black}], {0.165, 0.215}]]


 
$\endgroup$

1 Answer 1

4
$\begingroup$

Grayish edges in legend markers are caused by the default setting:

Legending`LegendDump`$DefaultMarkerStyle
EdgeForm[Directive[Opacity[0.3`], GrayLevel[0]]]

You can fix the issue in three different ways:

1. Use EdgeForm[Directive[Thick, Opacity[1], Blue]] instead of EdgeForm[Directive[Thick, Blue]] to get

enter image description here

2. Add the option BaseStyle -> EdgeForm[Opacity[1]] to PointLegend:

ListPlot[{{0.4, 38}, {0.5, 15}, {0.6, 10}}, Frame -> True, 
 FrameLabel -> {"a", "b"}, 
 PlotMarkers -> {Graphics[{EdgeForm[Directive[Thick, Blue]], White, 
     Rectangle[]}, ImageSize -> (15)]}, 
 PlotRange -> {{0.3, 0.7}, {0, 100}}, PlotRangePadding -> {0.05, 2}, 
 PlotLegends -> 
  Placed[PointLegend[{"data"}, BaseStyle -> EdgeForm[Opacity[1]], 
    LegendMarkerSize -> 14, 
    LabelStyle -> {FontSize -> 18, FontFamily -> "Arial", 
      Black}], {0.165, 0.215}]]

enter image description here

3. Set the value of Legending`LegendDump`$DefaultMarkerStyle to Opacity[1]:

Legending`LegendDump`$DefaultMarkerStyle = Opacity[1]

ListPlot[{{0.4, 38}, {0.5, 15}, {0.6, 10}}, Frame -> True, 
 FrameLabel -> {"a", "b"}, 
 PlotMarkers -> {Graphics[{EdgeForm[Directive[Thick, Blue]], White, 
     Rectangle[]}, ImageSize -> (15)]}, 
 PlotRange -> {{0.3, 0.7}, {0, 100}}, PlotRangePadding -> {0.05, 2}, 
 PlotLegends -> 
  Placed[PointLegend[{"data"}, LegendMarkerSize -> 14, 
    LabelStyle -> {FontSize -> 18, FontFamily -> "Arial", 
      Black}], {0.165, 0.215}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.