Skip to content

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

Closed

Description

@normanius

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

Activity

  1. anntzer commented on Aug 13, 2019

    @anntzer
    Contributor

    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.

  2. jkseppan commented on Jul 28, 2020

    @jkseppan
    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?

  3. normanius commented on Jul 28, 2020

    @normanius
    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

  4. QuLogic commented on Jul 28, 2020

    @QuLogic
    Member

    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

  5. QuLogic commented on Jul 28, 2020

    @QuLogic
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions