Skip to content

Adding hatches changes face color #14639

Closed as not planned
Closed as not planned

Description

@SMZ70

Bug report

Bug summary

Adding hatches results in a change in the face color of bars. The problem occurs when saved as PDF. Everything is ok with png.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.barh(2, 4, edgecolor='black', facecolor='green', alpha=0.3)
ax.barh(3, 4, edgecolor='black', facecolor='green', hatch='///', alpha=0.3)
fig.savefig('hbarplot.pdf')
fig.savefig('hbarplot.png')

Actual outcome

image

Expected outcome

The plot in the pdf file to be the same as the one in png file.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 3.0.3, conda, default
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg or module://ipykernel.pylab.backend_inline (problem occurs with both)
  • Python version: 3.7

Activity

  1. jklymak commented on Jun 26, 2019

    @jklymak
    Member

    Can you try a range of PDF viewers? This works fine on Apple Preview, and Adobe Acrobat.

  2. timhoffm commented on Jun 27, 2019

    @timhoffm
    Member

    Generated with 3.1: hbarplot.pdf

    This file is displayed correctly in Okular and Adobe Reader.

    @SMZ70 you can download this file and cross-check with your PDF viewer.

  3. SMZ70 commented on Jun 27, 2019

    @SMZ70
    Author

    Can you try a range of PDF viewers? This works fine on Apple Preview, and Adobe Acrobat.

    You're right. The problem is with Foxit Reader. Thanks!

  4. SMZ70 commented on Jun 27, 2019

    @SMZ70
    Author

    Generated with 3.1: hbarplot.pdf

    This file is displayed correctly in Okular and Adobe Reader.

    @SMZ70 you can download this file and cross-check with your PDF viewer.

    The file looks fine in Adobe Reader, but the problem exists with Foxit Reader. There must be something wrong with the viewer. Thanks!

  5. anntzer commented on Jun 27, 2019

    @anntzer
    Contributor

    The pdf is also misdisplayed by chromium.
    OTOH mplcairo generates a pdf that chromium reads fine.

  6. ImportanceOfBeingErnest commented on Jun 27, 2019

    @ImportanceOfBeingErnest
    Member

    There are continuously problems with matplotlib generated output on different pdf viewers.
    One thing I found to often work nicely is to save pdfs via svg and convert to pdf with inkscape.

    def savepdfviasvg(fig, name, **kwargs):
        import subprocess
        fig.savefig(name+".svg", format="svg", **kwargs)
        incmd = ["inkscape", name+".svg", "--export-pdf={}.pdf".format(name),
                 "--export-pdf-version=1.5"] #"--export-ignore-filters",
        subprocess.check_output(incmd)
    
        
    savepdfviasvg(fig, "hatchtestconv")
    
  7. timhoffm commented on Jun 27, 2019

    @timhoffm
    Member

    It's unclear if the PDF we generate is broken but handled gracefully by some viewers, or if we comply with the spec and the viewers are buggy. But to find out, somebody with experience in the PDF specification would be required.

  8. github-actions commented on Jun 21, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  9. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Jul 24, 2023
  10. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Jul 24, 2023
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