Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to produce a stand-alone PointLegend for a bunch of plots which I generated. Unfortunately, the markers are slightly off-axis. I have applied all the options discussed here, which did improve things, but not to perfection. Let me demonstrate the issue:

layout[pairs_] := 
 Row[Map[Row[{Pane[#[[1]], BaselinePosition -> Center], 
      Pane[#[[2]], BaselinePosition -> Center]}, 
     Alignment -> {Center, Center}, Frame -> True] &, pairs, 1]]

p = PointLegend[
  "DefaultPlotStyle" /. (Method /. 
     Charting`ResolvePlotTheme[Automatic, ListPlot]), Range[5], 
  LegendMarkers -> {Automatic, Large}, LegendLayout -> layout, 
  LegendFunction -> "Frame", 
  LabelStyle -> {FontFamily -> "Arial", FontSize -> 20}, 
  Alignment -> Center]

enter image description here

The diamond at item 3 is too low and the square at item 2 is too high. Here a screenshot with a horizontal ruler to prove the shift:

enter image description here

It takes a while to really see what is wrong but one immediately realizes that things are not well aligned. I don't think this can be used in a presentation.

Are there any mode options to force a true centering of the markers?

share|improve this question
    
Possible duplicate of mathematica.stackexchange.com/q/2214/3066 – m_goldberg 2 hours ago

I think this is a font issue. Look at:

Style[Row[{\[FilledCircle],\[FilledSquare],\[FilledDiamond]}], FontFamily->"Arial"]

enter image description here

The centering looks better in Times :

Style[Row[{\[FilledCircle],\[FilledSquare],\[FilledDiamond]}], FontFamily->"Times"]

enter image description here

Perhaps the following layout function will serve:

layout[pairs_] := Row @ Map[
    Row[{
        Show[#[[1]], BaselinePosition->Center, BaseStyle->{FontFamily->"Times"}],
        Pane[#[[2]], BaselinePosition->Center]
    }, Frame->True]&,
    pairs
]

This is what I get:

p = PointLegend[
    "DefaultPlotStyle" /. (Method/.Charting`ResolvePlotTheme[Automatic,ListPlot]),
    Range[5],
    LegendMarkers->{Automatic, Large},
    LegendLayout->layout,
    LegendFunction->"Frame",
    LabelStyle->{FontFamily->"Arial", FontSize->20}
]

enter image description here

share|improve this answer
    
(+1) I always thought that FontFamily doesn't affect such symbols as \[FilledCircle] in any way because they are taken from the Mathematica's own font. It is weird that FontFamily changes size and positioning. How can it be explained? – Alexey Popkov 4 hours ago

It is well known that the default markers are font glyphs and Mathematica can't position font glyphs precisely. If you need precise positioning, you should use primitive-based LegendMarkers. For this purpose I recommend my package PolygonPlotMarkers`:

Needs["PolygonPlotMarkers`"]

markers = {
   Graphics[{FaceForm[ColorData[97][1]], EdgeForm[], PolygonMarker["Disk", Offset[20]]}],
   Graphics[{FaceForm[ColorData[97][2]], EdgeForm[], PolygonMarker["Square", Offset[20]]}],
   Graphics[{FaceForm[ColorData[97][3]], EdgeForm[], PolygonMarker["Diamond", Offset[20]]}],
   Graphics[{FaceForm[ColorData[97][4]], EdgeForm[], PolygonMarker["UpTriangle", Offset[20]]}],
   Graphics[{FaceForm[ColorData[97][5]], EdgeForm[], PolygonMarker["DownTriangle", Offset[20]]}]};

pl1 = PointLegend[ColorData[97] /@ Range[5], Range[5], LegendMarkerSize -> 30, 
  LegendMarkers -> markers, LegendLayout -> "Row", 
  LabelStyle -> {FontFamily -> "Arial", FontSize -> 30}]

{w, h} = ImageDimensions@Rasterize[pl1, "Image"];

Graphics[{Inset[pl1, {0, 0}, {0, 0}, Automatic], Line[{{-1, 0}, {1, 0}}]}, 
 AspectRatio -> h/w, ImageSize -> w]

enter image description here

enter image description here

Note that in the above all the markers are centered relative to their bounding boxes, while on the plot they will be placed at the centers of mass. It is not too difficult to create a legend where markers will be aligned vertically at their centers of mass and the labels aligned at their centers:

align = {BaselinePosition -> Axis, ImageSize -> 30, Axes -> True, Ticks -> False, 
   AxesOrigin -> {0, 0}};
Row[Row /@ Transpose[{Append[#, align] & /@ markers, 
    Row[{#}, BaselinePosition -> Center, 
       BaseStyle -> {FontFamily -> "Arial", FontSize -> 30}] & /@ Range[5]}], Spacer[14]]

legend

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.