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

Skip to content

Fix hatch linewidth in PGF #24263

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,17 @@ def draw_path(self, gc, path, transform, rgbFace=None):
r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}")
_writeln(self.fh, r"\pgfusepath{clip}")
scale = mpl.transforms.Affine2D().scale(self.dpi)
# Store default PGF line width
_writeln(self.fh, r"\newlength{\defaultpgflinewidth}")
_writeln(self.fh,
r"\setlength{\defaultpgflinewidth}{\pgflinewidth}")
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)
# Restore default PGF line width
_writeln(self.fh, r"\pgfsetlinewidth{\defaultpgflinewidth}")
_writeln(self.fh, r"\end{pgfscope}")
_writeln(self.fh, r"}")
# repeat pattern, filling the bounding rect of the path
Expand Down
Binary file not shown.
14 changes: 12 additions & 2 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.testing import _has_tex_package, _check_for_pgf
from matplotlib.testing.exceptions import ImageComparisonFailure
from matplotlib.testing.compare import compare_images
from matplotlib.backends.backend_pgf import PdfPages
from matplotlib.testing.exceptions import ImageComparisonFailure
from matplotlib.backends.backend_pgf import FigureCanvasPgf, PdfPages
from matplotlib.testing.decorators import (
_image_directories, check_figures_equal, image_comparison)
from matplotlib.testing._markers import (
Expand Down Expand Up @@ -400,3 +400,13 @@ def test_document_font_size():
label=r'\normalsize the document font size is \the\fontdimen6\font'
)
plt.legend()


@needs_pgf_xelatex
@pytest.mark.backend('pgf')
@image_comparison(['hatch_linewidth'], extensions=['pdf'])
def test_pgf_hatch_linewidth():
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
mpl.rcParams['hatch.linewidth'] = 0.1

plt.bar(1, 1, color='white', edgecolor='black', hatch='/')
Loading