diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 48b6e8ac152c..fbc33e955563 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -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 diff --git a/lib/matplotlib/tests/baseline_images/test_backend_pgf/hatch_linewidth.pdf b/lib/matplotlib/tests/baseline_images/test_backend_pgf/hatch_linewidth.pdf new file mode 100644 index 000000000000..956f6070e6ec Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_backend_pgf/hatch_linewidth.pdf differ diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index e218a81cdceb..4c83d48f037a 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -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 ( @@ -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='/')