Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Using PlotLegends with a PlotStyle containing (for instance) PointSize[0.02] creates a legend that does not match the plot.

ListPlot[Table[RandomReal[NormalDistribution[], {20, 2}], {2}],
 PlotLegends -> {"a", "b"}, PlotStyle -> PointSize[0.02]]

enter image description here

How can I get a sensible legend when using a number with PointSize? Solutions involving named sizes (like PointSize[Medium]) are inadmissible unless they somehow create points that have a constant size relative to the plot size.

share|improve this question

3 Answers 3

up vote 13 down vote accepted

This problem often occurs in plotting and graphics because of the use of Foo instead of AbsoluteFoo for the directives. The former uses sizes relative to the plot size, whereas the latter, as the name suggests, uses absolute sizes.

In the built-in plot legends in version 9, the plot and the legend are actually two separate objects which are just combined, hence PointSize uses the figure size of each of those to compute what 0.02 means. All you need to do is to change it to AbsolutePointSize to keep it consistent between the two. Of course, the argument will also change and AbsolutePointSize[7] looks close enough to what you were gunning for.

share|improve this answer
    
Thanks for your answer. I'm disappointed because this kind of trial end error is what I had hoped would be eliminated by the new legends capabilities. I'd say it's not mature yet. –  ArgentoSapiens Jan 10 '13 at 18:05

In version 10 the PointSize of the legend will automatically match the PointSize of the Plot:

ListPlot[Table[RandomReal[NormalDistribution[], {20, 2}], {2}], 
  PlotLegends -> {"a", "b"}, PlotStyle -> PointSize[0.02]]

MmaVersion10


Edit: The answer by @eldo made me realize, that this is only true up to a PointSize that is equal to the default LegendMarkerSize. To get bigger matching PointSizes:

ListPlot[Table[RandomReal[NormalDistribution[], {20, 2}], {2}], 
 PlotStyle -> AbsolutePointSize[15], 
 PlotLegends -> PointLegend[{"a", "b"}, LegendMarkerSize -> 15]]

evenBiggerPoints

For further testing you can use:

Manipulate[
 ListPlot[Table[RandomReal[NormalDistribution[], {20, 2}], {2}], 
  PlotStyle -> AbsolutePointSize[ps], 
  PlotLegends -> PointLegend[{"a", "b"}, LegendMarkerSize -> ps]],
 {ps, 1, 50}]
share|improve this answer
    
Excellent @Karsten ! I was already working on complicated things :) –  eldo Aug 13 at 14:59
    
@eldo Agree. They improved the PlotLegends, but some things still don't work as automated and intuitive as they should and one ends up doing way to complicated stuff. –  Karsten 7. Aug 13 at 15:11
    
BTW, Chapeau for collecting 1.651 pennies within 33 days of membership. Hope your website will pop up soon. –  eldo Aug 13 at 18:54

My V10 output doesn't agree with Karsten's answer, f.e.:

ListPlot[Table[RandomReal[NormalDistribution[], {20, 2}], {2}],
 PlotLegends -> {"a", "b"},
 PlotStyle -> PointSize[0.05]]

enter image description here

I tried to fix this by building my own PointLegend:

PointLegend[{
  Directive[Blue, AbsolutePointSize[20]],
  Directive[Orange, AbsolutePointSize[20]]},
 {"a", "b"}]

enter image description here

Unfortunately, above a certain AbsolutePointSize the points don't grow anymore but mutate to rectangles.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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