"PlotLegend" non visualizza il colore del simbolo corretto

Oct 15 2020

Sto tracciando alcuni punti dati con una legenda ma PlotLegendnon restituisco lo stesso colore dei punti. Dov'è l'errore?

Ecco il risultato che ottengo: [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}]]


 

Risposte

4 kglr Oct 15 2020 at 19:10

I bordi grigiastri nei marcatori della legenda sono causati dall'impostazione predefinita:

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

Puoi risolvere il problema in tre modi diversi:

1. Utilizzare EdgeForm[Directive[Thick, Opacity[1], Blue]]invece di EdgeForm[Directive[Thick, Blue]]per ottenere

2. Aggiungi l'opzione BaseStyle -> EdgeForm[Opacity[1]]a 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}]]

3. Imposta il valore di Legending`LegendDump`$DefaultMarkerStylesu 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}]]