Clipping of graphs.

Dear All,

I have several graphs next to each other, in Mathematica it looks like this:

However in the exported PDF it looks like this:

ScreenShot2015-02-03at14.56.07.png

Is there a way to get these clipping masks correct? I set PlotRangeClipping to True and I have set the correct PlotRange.

I’ve often found exporting to eps works better, then you can convert that to pdf. Perhaps this will work for you.

Hi Chip,

I tried that as well, to no avail. Same problem persists. Any idea if we can manually add a clipping mask with proper coordinates?
Of course I can edit the output figure (eps/pdf) in illustrator. But this gets very tiresome with many figures.

Thanks for the suggestion though.

If this is a GraphicsGrid or GraphicsRow you might try Rasterize on it, then export the rasterized version.

Hi David,

It is not a GraphicsGrid/Row/Column. It is one Graphics object with several Inset objects because GraphicsGrid are very unreliable with styling, paddings et cetera. I can’t have it rasterized though, I need the figure to be vector.
Some parts of the figure are vectorised actually; the density maps are rasterized and placed back in to the figures using Prolog. This is merely done to save some on the file-size.
Thanks for the suggestion though!

The problem though is way more general, even the simplest example goes wrong (in view and in export).

Graphics[{Pink, Disk[{0, 0}, 5]}, Frame -> True, PlotRange -> 4, PlotRangeClipping -> True]
Export["out.pdf", %]

Any more ideas? This seems like a bug, I’m open for spelunking and underground solutions creating clipping masks or hacks to fix this…

Hi Sander,
I think it’s a bug, but it may be in the import rather than the export. When I look at the pdf with Acrobat it’s much better.

SetDirectory[NotebookDirectory[]];

p1 = Graphics[{Pink, Disk[{0, 0}, 5]}, Frame -> True, PlotRange -> 4, 
  PlotRangeClipping -> True]

 Export["out.pdf", p1];

Import["out.pdf"]

But when I look at out.pdf with Acrobat or Photoshop I see this: (Converted to png for posting)

I’m not using the import feature, only the export. It should just be perfect, I don’t see what is the problem. The positions (in pdf units) for the clipping ranges are known; the exact coordinates as for the frame!

I’d like to hear from someone from Wolfram…

EDIT: I think it just completely ignores the clipping masks in the Import.

I see what you mean, Sander. Even in my example, the colored region of the pdf now laps over the top and bottom of the frame. Through the years, I have had a lot of problems getting pdf output that actually looked like the Mathematica graphic. Sometimes I have noticed that the results interact strongly with as-drawn and export image sizes.

Best, David

Generally it is fine, but clipping masks are always troublesome! They are somehow very difficult to handle. I made some complaints before but they never seem to fix them.

It would be very nice if there would be a clipping-mask primitive in one of the future versions, so you manually mask something!

–SH