Skip to content

[Bug]: Exported PDF figures cannot be modified by Adobe Illustrator correctly. #27893

Open

Description

@JerrySoybean

Bug summary

Use imshow to generate a figure, and then save it as a pdf file. If you open the generated pdf figure in Adobe Illustrator, the figure in Adobe Illustrator becomes different. Colors are wrongly assigned.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

import matplotlib
print(matplotlib.__version__)

a = np.array([[1, 2, 3], [4, 5, 6]])
plt.matshow(a)
plt.savefig(‘test.pdf’)

Actual outcome

image

Expected outcome

image

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.10.13

Jupyter version

7.0.8

Installation

conda

Activity

  1. jklymak commented on Mar 9, 2024

    @jklymak
    Member

    Please show your full code. Also do other viewers work?

  2. JerrySoybean commented on Mar 13, 2024

    @JerrySoybean
    Author

    Please show your full code. Also do other viewers work?

    That's all the code I use. Only Adobe Illustrator doesn't work correctly.

  3. timhoffm commented on Mar 13, 2024

    @timhoffm
    Member

    Please show your full code. Also do other viewers work?

    That's all the code I use. Only Adobe Illustrator doesn't work correctly.

    The shown code is certainly not complete. It only imports matplotlib and creates a numpy array. It does not call any matplotlib functions.

  4. JerrySoybean commented on Mar 19, 2024

    @JerrySoybean
    Author

    Please show your full code. Also do other viewers work?

    That's all the code I use. Only Adobe Illustrator doesn't work correctly.

    The shown code is certainly not complete. It only imports matplotlib and creates a numpy array. It does not call any matplotlib functions.

    Sorry, I’ve updated the code. Thanks for this reminding.

  5. jklymak commented on Mar 19, 2024

    @jklymak
    Member

    I can reproduce this with Illustrator 2023. But given that every other viewer handles this properly, including Acrobat and Photoshop, my tendency is to blame Illustrator.

  6. tacaswell commented on Mar 22, 2024

    @tacaswell
    Member

    Can someone with a valid illustrator license report this as a bug to them? The pdf spec is complicated enough that it is possible that they have a bug, but it is also possible that we are emitting technically incorrect files and the other viewers are all buggy-in-a-useful-way or there is some undefined behavior gets lucky most of the time.

    My guess is that something is going wrong with images use color palates which we recently fixed some bug with. Does this work with older versions of mpl?

  7. jklymak commented on Mar 22, 2024

    @jklymak
    Member

    Fair enough - this bisects to PR #25704. Before 8d42212 the colors look fine in Illustrator

    I'm having a little conceptual trouble understanding why that would have caused the problem though....

  8. JerrySoybean commented on Apr 1, 2024

    @JerrySoybean
    Author

    I can reproduce this with Illustrator 2023. But given that every other viewer handles this properly, including Acrobat and Photoshop, my tendency is to blame Illustrator.

    But the thing is, it's because of the upgrade of matplotlib that changes the outcome in Illustrator? And I'm not sure can acrobat and Photoshop modify PDF as the way used in Illustrator?

  9. tacaswell commented on Apr 1, 2024

    @tacaswell
    Member

    However the question remains if we are emitting a valid by the spec PDF or not. We have in the past exposed bugs in other renders (notably clipping details in librvg).

    I think the options are:

    • we used to emit valid pdfs and after that change we no longer do but every renderer but illustrator is forgiving in the same way so it still looks OK
    • we are emitting valid pdf both before and after that PR but illustrator's intake code has a bug and is failing on the new pdfs

    I think either is equally likely so I think what needs to happen here is:

    1. we need to generate the simplest possible pdf that fails not and did not in older versions of Matplotlib
    2. either decompress them (or generate them without compression) and diff them
    3. look up the spec on what changed to see if we are violating it or not
  10. QuLogic commented on Apr 1, 2024

    @QuLogic
    Member

    Fair enough - this bisects to PR #25704. Before 8d42212 the colors look fine in Illustrator

    Hmm, are you sure this is the correct commit? If I run the original code, I get the same PDF output (other than the creator metadata).

  11. jklymak commented on Apr 1, 2024

    @jklymak
    Member

    Not 100% sure. Bisecting a problem like this is a lot of manual opening and closing of files so I may have messed up

  12. mxposed commented on Jul 1, 2025

    @mxposed

    I have run into this bug. Attaching 2 pdfs generated with the same code, from v 3.7.2 (which I confirm the issue in Illustrator 2024) and from 3.3.4 where there is no issue

    test_3.7.2.pdf
    test_3.3.4.pdf

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