Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Hatch line width ignored with pgf backend #15491

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

Open
victorkristof opened this issue Oct 23, 2019 · 10 comments · May be fixed by #24263
Open

Hatch line width ignored with pgf backend #15491

victorkristof opened this issue Oct 23, 2019 · 10 comments · May be fixed by #24263
Labels
backend: pgf keep Items to be ignored by the “Stale” Github Action status: confirmed bug status: has patch patch suggested, PR still needed

Comments

@victorkristof
Copy link

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.

@timhoffm
Copy link
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.

@m-wells
Copy link

m-wells commented Mar 20, 2020

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.

@anntzer
Copy link
Contributor

anntzer commented May 20, 2020

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 :)

@pspiagicw
Copy link

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

@timhoffm
Copy link
Member

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

@pspiagicw
Copy link

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.

@QuLogic QuLogic added the status: has patch patch suggested, PR still needed label Aug 25, 2021
@timhoffm
Copy link
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.

@oscargus oscargus linked a pull request Oct 24, 2022 that will close this issue
6 tasks
@github-actions
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 28, 2023
@QuLogic
Copy link
Member

QuLogic commented Jun 30, 2023

There is an open PR for this.

@QuLogic QuLogic added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 30, 2023
@daeh
Copy link

daeh commented Sep 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: pgf keep Items to be ignored by the “Stale” Github Action status: confirmed bug status: has patch patch suggested, PR still needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants