Skip to content

pdf-backend for savefig produces unusual grouping within pdf element #15051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
normanius opened this issue Aug 13, 2019 · 5 comments
Closed

pdf-backend for savefig produces unusual grouping within pdf element #15051

normanius opened this issue Aug 13, 2019 · 5 comments

Comments

@normanius
Copy link

Bug report

Bug summary

When saving the figure as a PDF, the items are grouped unusually, which leads to unexpected results when shown in a viewer that supports knockout effects.
While this is not problematic most of the time, the issue causes troubles if the PDF created by matplotlib is edited within Illustrator (possibly other PDF editors as well).

Code for reproduction

import matplotlib.pyplot as plt
x = [42,43,44]
y=[42,43,44]
plt.scatter(x,y,alpha=0.7,sizes=[500], linewidths=[5])
plt.savefig('sample.pdf')

Actual outcome
Because I initially thought this is an Illustrator related problem, I posted a (very detailed) description in one of the Adobe Forums.

In (MacOS) Preview.app
image

In Adobe Illustrator:
image

In the Adobe Illustrator forum I got the feedback that the grouping of the items is unusual and causes the confusion. Indeed, ungrouping the elements resolved all of my problems.

Expected outcome
Same as in default preview app.

Matplotlib version

  • MacOS 10.14.5
  • Matplotlib v3.1.1
  • Matplotlib backend: MacOSX
  • Python 3.6.7
@anntzer
Copy link
Contributor

anntzer commented Aug 13, 2019

I can repro this issue with mupdf/ghostscript, but not with poppler (okular). Not sure whether it's the readers not following the spec, or not.
fwiw https://github.com/matplotlib/mplcairo generates pdfs without this issue.

@jkseppan
Copy link
Member

Since ungrouping in Adobe Illustrator solves the problem, could you share

(1) a small problematic file from matplotlib;
(2) the same file after ungrouping in Illustrator and saving as PDF?

@normanius
Copy link
Author

Here you are. Since Illustrator supports different versions of PDF, I've picked the newest and oldest available version (1.3 and 1.7).

I used the above sample code to create the PDF (sample-original.pdf). The only action performed in Illustrator was to ungroup the items (Cmd+Shift+G), followed by "Save as".

sample-original.pdf
sample-ungrouped-pdf1.3.pdf
sample-ungrouped-pdf1.7.pdf

@QuLogic
Copy link
Member

QuLogic commented Jul 28, 2020

I don't think we set knockout groups; I think this is an implicit behaviour in PDF:
Screenshot from 2020-07-28 18-50-59
Screenshot from 2020-07-28 18-51-25

@QuLogic
Copy link
Member

QuLogic commented Jul 28, 2020

So I think that makes this a duplicate of #10035.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants