4

I have found the custom plotmarkers package developed by @Alexey Popkov extremely handy for makeing nice, accurate plots. However, I have run into a small issue that I am struggling to make sense of. If I create a graphic object and combine with basic point data in a ListPlote.g.,

Show[
 Graphics[{LightGray, Rectangle[{0, 0}, {100, 100}]}], 
 ListPlot[{{22, 57}, {88, 91}}, Axes -> False]]

I get the following

grey sq and dots

which I expect.

However, if I try use the PloygonPlotMarkers package e.g.,

Needs["PolygonPlotMarkers`"]
(* https://mathematica.stackexchange.com/questions/84857/how-can-we-\
make-publication-quality-plotmarkers-without-version-10 *)

fm[name_, size_: 7] := 
  Graphics[{EdgeForm[], PolygonMarker[name, Offset[size]]}, 
   AlignmentPoint -> {0, 0}];
(* making markers for plotting -filled*)

Show[Graphics[{LightGray, Rectangle[{0, 0}, {100, 100}]}],
 ListPlot[{{22, 57}, {88, 91}},
  PlotMarkers -> fm["Cross", 6],
  PlotStyle -> Red,
  Axes -> False]]

the result is unexpected:

enter image description here

There is only a single point rendered and no Rectangle. Adding a PlotRange ->... specification within ListPlot produces the same unsatisfactory result, however, if I add a PlotRange -> ... to Show everything plots fine:

enter image description here

This may not seem like a huge problem here but what I am posting is very much a MWE and this issue gets in the way in more involved plotting overlays.

I suspect there is some issue with padding around the custom plotmarkers, however, I can't see where it is coming from. I also suspect that in the second example all three items are plotted (two crosses and the rectangle) but very small.

Can anyone explain why this is happening and suggest a solution that resolves things a bit more satisfactorily than adding PlotRange to Show?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
geordie
  • 3,693
  • 1
  • 26
  • 33
  • 1
    You can add ImageSize -> {Automatic, 3 size} to the Graphics expression in the definition of fm, which fixes the issue. Unfortunately, I'm not sure why exactly this works – Lukas Lang Feb 02 '19 at 09:11
  • @LukasLang, yep this fixes the problem! Considering all that we want to do is render a small glyph, adding a scaled ImageSize declaration is unlikely to cause broader problems in implementation. This should perhaps be written as an answer. – geordie Feb 02 '19 at 11:42

2 Answers2

2

This problem appears to be due to the image padding:

Show[
 Graphics[{LightGray, Rectangle[{0, 0}, {100, 100}]}],
 ListPlot[
  {{22, 57}, {88, 91}},
  PlotMarkers -> fm["Cross", 6],
  PlotStyle -> Red,
  Axes -> False
  ],
 ImagePadding -> None
 ]

Mathematica graphics

It might be related to this Q&A.

The reason why adding PlotRange works may be because it helps the heuristic that calculates the image padding to choose a better value, but the underlying problem is not that the plot range is wrong to begin with. Let's call your problematic graphics gr, then

PlotRange /. AbsoluteOptions[gr]

{{0., 100.}, {0., 100.}}

C. E.
  • 70,533
  • 6
  • 140
  • 264
1

As mentioned in the comments, adding an explicit ImageSize setting seems to do the trick:

fm[name_, size_: 7] := Graphics[
   {
    EdgeForm[],
    PolygonMarker[name, Offset[size]]
    },
   AlignmentPoint -> {0, 0},
   ImageSize -> {Automatic, 3 size}
   ];

Show[
 Graphics[{LightGray, Rectangle[{0, 0}, {100, 100}]}],
 ListPlot[{{22, 57}, {88, 91}}, PlotMarkers -> fm["Cross", 6], PlotStyle -> Red, Axes -> False]
 ]

enter image description here

I'm not sure why exactly this works, but this solution is fully contained in the definition of fm, which should make it more userfriendly

Lukas Lang
  • 33,963
  • 1
  • 51
  • 97