8
$\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

10
$\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$
4
$\begingroup$

I fiddled around a bit. LegendMarkerSize is really counterintuitive. Apparently, 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$
6
  • $\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
    Dec 11, 2023 at 20:29
  • $\begingroup$ Hm. I don't understand what you mean. $\endgroup$ Dec 11, 2023 at 20:42
  • $\begingroup$ Oops. I guess my comment didn't make as much sense as I thought. I meant that in my example the LegendMarkerSize does determine the size of the actual markers in the legend and not the Graphics containing the whole legend. It is not a matter of the Mathematica version though as I ran your code and there it does not change them. It seems to depend on the type of LegendMarkers that you use. $\endgroup$
    – Kvothe
    Dec 12, 2023 at 13:15
  • $\begingroup$ For a simpler example just replace your LegendMarkers above with LegendMarkers -> {Charting`CommonDump`GraphicsPlotMarkers[][[1]]} $\endgroup$
    – Kvothe
    Dec 12, 2023 at 13:16
  • $\begingroup$ Okay, the bullets in the legend get larger. What is the problem? $\endgroup$ Dec 12, 2023 at 13:35

Your Answer

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

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