3
$\begingroup$

Bug introduced in 9.0 or earlier and persisting through 11.0


I'd like to create a PointLegend with various shapes, a diamond (rotated square) being one of them.

I'm not sure why this doesn't work with the following code:

PointLegend[
 ColorData[97, "ColorList"], {"One", "Two", "Three", "Four"}, 
 LegendMarkerSize -> Large, 
 LegendMarkers -> 
  Graphics /@ {Rectangle[], Disk[], Rotate[Rectangle[], Pi/4], 
    Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]}]

Code Output

Any suggestions?

$\endgroup$
  • $\begingroup$ It's annoying that it behaves this way, but this is a workaround: GeometricTransformation[Rectangle[], RotationTransform[Pi/4]] instead of Rotate[Rectangle[], Pi/4] $\endgroup$ – Jason B. Aug 1 '16 at 15:21
  • $\begingroup$ Or alternatively: Polygon[{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}] $\endgroup$ – Feyre Aug 1 '16 at 15:23
2
$\begingroup$

Another option is to use symbols:

PointLegend[
 ColorData[97, "ColorList"], {"One", "Two", "Three", "Four"},
 LegendMarkerSize -> {25},
 LegendMarkers -> {{"\[FilledSmallSquare]", 20}, 
                   {"\[FilledSmallCircle]", 20}, 
                   {"\[FilledDiamond]", 20}, 
                   {"\[FilledUpTriangle]", 20}}]

enter image description here

$\endgroup$
3
$\begingroup$

This is not an answer. It is a long comment that doesn't fit in a comment.

We can see what sorts of graphics are generated by using ToBoxes, then extracting the GraphicsBox and finally using ToExpression to convert it back to Graphics. After removing several irrelevant things from those graphics and simplifying a bit, we end up with

Graphics[{Inset[Graphics[GeometricTransformation[Rectangle[{0, 0}], 
            {{{0.7071067811865475, -0.7071067811865475}, {0.7071067811865475, 
                  0.7071067811865475}}, Center}], 
    DefaultBaseStyle -> 
            { Directive[EdgeForm[Red],
              RGBColor[0.368417, 0.506779, 0.709798]]}], 
   Scaled[{1/2, 1/2}], Automatic, Scaled[1]]}]

This renders as empty. Removing the GeometricTransformation part allows it to render properly. Removing the EdgeForm directive also fixes it. Removing the last argument of Inset (Automatic) also fixes it.

This looks like a bug.

$\endgroup$

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