3
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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 $\endgroup$ – Lukas Lang Feb 2 at 9:11
  • $\begingroup$ @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. $\endgroup$ – geordie Feb 2 at 11:42
1
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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.}}

$\endgroup$
  • $\begingroup$ Yes, it sounds like this is related. Thanks for the insight. $\endgroup$ – geordie Feb 2 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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