Skip to content

Hatch line width ignored with pgf backend #15491

Closed

Description

@victorkristof

Bug report

Bug summary

The hatch line width does not take effect when saving figure with the pgf backend. It is always drawn with a width of 1.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.backends.backend_pgf import FigureCanvasPgf

mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
mpl.rcParams['hatch.linewidth'] = 0.1  

plt.bar(1, 1, color='white', edgecolor='black', hatch='/')
plt.savefig('hatch.pdf')  # Hatch line width will be 1.
plt.show()  # Hatch line width will be 0.1 as expected.

Actual outcome

hatch-bad

Expected outcome

hatch-good

Matplotlib version

  • Operating system: macOS 10.14.6
  • Matplotlib version: 3.1.1
  • Matplotlib backend: pgf
  • Python version: 3.6.3

Matplotlib installed via pip.

Activity

  1. timhoffm commented on Oct 26, 2019

    @timhoffm
    Member

    Starting point for fix is likely RendererPgf.draw_path(). The linewidth is available via gc.get_hatch_linewidth(). Now we only need somebody who understands pgf.

    Note: mpl.rcParams['hatch.color'] is also broken, but on a more fundamental level. It does not work for other renderers either.

  2. m-wells commented on Mar 20, 2020

    @m-wells

    Calling set_rasterized(True) on each bar element (individually) allows for me to use hatching without any issue. Not ideal but a good workaround for me.

  3. anntzer commented on May 20, 2020

    @anntzer
    Contributor

    Looks like this is fixed by

    diff --git i/lib/matplotlib/backends/backend_pgf.py w/lib/matplotlib/backends/backend_pgf.py
    index d68c743b7..38589ad65 100644
    --- i/lib/matplotlib/backends/backend_pgf.py
    +++ w/lib/matplotlib/backends/backend_pgf.py
    @@ -487,6 +487,10 @@ class RendererPgf(RendererBase):
                         r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}")
                 writeln(self.fh, r"\pgfusepath{clip}")
                 scale = mpl.transforms.Affine2D().scale(self.dpi)
    +            lw = (mpl.rcParams["hatch.linewidth"]
    +                  * mpl_pt_to_in * latex_in_to_pt)
    +            writeln(self.fh, r"\pgfsetlinewidth{%fpt}" % lw)
                 self._print_pgf_path(None, gc.get_hatch_path(), scale)
                 self._pgf_path_draw(stroke=True)
                 writeln(self.fh, r"\end{pgfscope}")

    Feel free to pick up the patch :)

  4. pspiagicw commented on Aug 24, 2021

    @pspiagicw

    Has this issue been fixed in some later PR ? If yes we should close this

  5. timhoffm commented on Aug 24, 2021

    @timhoffm
    Member

    Likely not, otherwise the PR would be linked here. Have you any reason to believe this has been fixed?

  6. pspiagicw commented on Aug 25, 2021

    @pspiagicw

    The change needed seems to be a few lines , too low for a dedicated PR . If needed I can make a PR and close this issue.

  7. timhoffm commented on Aug 25, 2021

    @timhoffm
    Member

    Developer resources are limited. Therefore also seemingly simple fixes may sometimes lie around or fall through the cracks.

    You're are very welcome to provide a PR. Please provide a test if possible as well.

  8. github-actions commented on Jun 28, 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. QuLogic commented on Jun 30, 2023

    @QuLogic
    Member

    There is an open PR for this.

  10. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Jun 30, 2023
  11. daeh commented on Sep 13, 2024

    @daeh

    Just adding enthusiastic support behind this issue being resolved. It's continuing to cause problems.

  12. added this to the v3.11.2 milestone on Sep 3, 2026
  13. QuLogic commented on Sep 3, 2026

    @QuLogic
    Member

    This was fixed by #32254.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions