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.

While answering Change the inner color of markers I came across a behavior that may be a bug.
I would like to know if there is another explanation.

First a basic example of normal behavior:

ListLinePlot[{Prime~Array~12, Fibonacci~Array~12},
 PlotMarkers -> Graphics[{Brown, Rectangle[]}, ImageSize -> 13],
 PlotLegends -> Automatic
]

enter image description here

Note that the markers are included in the legend. But now if I Rotate the Rectangle:

ListLinePlot[{Prime~Array~12, Fibonacci~Array~12},
 PlotMarkers -> Graphics[{Brown, Rectangle[] ~Rotate~ (Pi/4)}, ImageSize -> 13],
 PlotLegends -> Automatic
]

enter image description here

The markers disappear from the legend. They do appear if I Rotate the entire Graphics, however the markers are not scaled as before and they clip:

ListLinePlot[{Prime~Array~12, Fibonacci~Array~12},
 PlotMarkers -> Graphics[{Brown, Rectangle[]}, ImageSize -> 13] ~Rotate~ (Pi/4),
 PlotLegends -> Automatic
]

enter image description here

  1. Is use of Rotate in plot markers simply unsupported or is this a bug?

  2. Is there a way to use rotated primitives for markers and not break the legend?

share|improve this question

2 Answers 2

A workaround is to use GeometricTransformation instead of Rotate. By specifying coordinates in the Offset form we can achieve consistent size of markers on the plot and in the legend. The cropping of the markers in the legend can be avoided by increasing their sizes as MinHsuan Peng suggests:

ListLinePlot[{Prime~Array~12, Fibonacci~Array~12}, 
 PlotMarkers -> 
  Graphics[{Brown, 
    GeometricTransformation[
     Rectangle[Offset[{-5, -5}], Offset[{5, 5}]], 
     RotationTransform[Pi/4]]}], 
 PlotLegends -> LineLegend[Automatic, LegendMarkerSize -> {40, 15}]]

plot

As to whether it is a bug, I think it is because Rotated rectangles appear inside of the the code of the legend but are not shown. Even specifying them in the Offset form does not produce correct plot but reveals even more strange bugs:

ListLinePlot[{Prime~Array~12, Fibonacci~Array~12}, 
 PlotMarkers -> 
  Graphics[{Brown, 
    Rectangle[Offset[{-5, -5}], Offset[{5, 5}]]~Rotate~(Pi/4)}, 
   ImageSize -> 10], PlotLegends -> Automatic]

plot2

share|improve this answer

A workaround to question 2 is to increase legend marker size:

LineLegend[Automatic, LegendMarkerSize -> {40, 20}]

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.