7
$\begingroup$

I'm trying to plot multiple plots in just one. I need to have small markers inside the plot, but in the legend it would be more convenient to have bigger markers.

I'm trying to change LegendMarkerSize, but it only changes the shape of the whole legend (without changing the size of the points). Here's an example of my struggle:

I have:

ListPlot[{Prime[Range[25]], Sqrt[Range[40]]}, 
 PlotMarkers -> {Automatic, 3}, 
 PlotLegends -> 
  PointLegend[{"Primes", "Roots"}, LegendMarkerSize -> 3, 
   LegendFunction -> None, LegendLabel -> "Legend"]]

enter image description here

And changing only LegendMarkerSize from 3 to (say) 23, I get:

ListPlot[{Prime[Range[25]], Sqrt[Range[40]]}, 
PlotMarkers -> {Automatic, 3}, 
PlotLegends -> 
 PointLegend[{"Primes", "Roots"}, LegendMarkerSize -> 23, 
 LegendFunction -> None, LegendLabel -> "Legend"]]

enter image description here

As you can see, only the text have shifted. How can I increase the size of the markers inside the legend without modifying the size of the markers in the plot on itself?

Thank you very much.

$\endgroup$

2 Answers 2

9
$\begingroup$

Update: To have the legend markers match the markers in plot, you can add the option LegendMarkers -> ChartElementData["SimpleMarkers"][[All,1]] in SwatchLegend:

ListPlot[{Prime[Range[25]], Sqrt[Range[40]],Log@Range[40]}, 
 PlotMarkers -> {Automatic, 9}, 
 PlotLegends -> SwatchLegend[{"Primes", "Roots", "Logs"}, LegendMarkerSize -> 15, 
   LegendMarkers -> ChartElementData["SimpleMarkers"][[All,1]], 
   LegendLabel -> Style["Legend", 20]]] 

enter image description here

Original answer:

You can use SwatchLegend with options LegendMarkers -> "Bubble" and LegendMarkerSize -> 15:

ListPlot[{Prime[Range[25]], Sqrt[Range[40]]}, 
 PlotMarkers -> {Automatic, 3}, 
 PlotLegends ->  SwatchLegend[{"Primes", "Roots"}, LegendMarkerSize -> 15, 
   LegendMarkers -> "Bubble",  LegendLabel -> Style["Legend", 20]]]

enter image description here

$\endgroup$
3
$\begingroup$

I fiddled around a bit. LegendMarkerSize is really counterintuitive. Apperently, it does only control the size of the Graphics containing the markers, not the markers themselfes. How is this?

ListPlot[{Prime[Range[25]], Sqrt[Range[40]]},
 PlotMarkers -> {Automatic, 3},
 PlotLegends -> PointLegend[
   {"Primes", "Roots"},
   LegendMarkerSize -> 15,
   LegendMarkers -> {{"\[FilledCircle]", 15}},
   LegendLabel -> Style["Legend", FontSize -> 20]
   ]
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ Has this changed? See: PointLegend[{Red, Red, Green, Blue, Black}, Range[10] , LegendMarkerSize -> 90, LegendMarkers -> {Charting`CommonDump`GraphicsPlotMarkers[][[1]], Charting`CommonDump`GraphicsOpenPlotMarkers[][[1]], Charting`CommonDump`GraphicsPlotMarkers[][[3]], Charting`CommonDump`GraphicsPlotMarkers[][[1]]} ] or does it depend on where the option gets used? $\endgroup$
    – Kvothe
    18 mins ago
  • $\begingroup$ Hm. I don't understand what you mean. $\endgroup$ 5 mins ago

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.