diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 48b6e8ac152c..48831a3716c4 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -384,8 +384,7 @@ def __init__(self, figure, fh): self.figure = figure self.image_counter = 0 - def draw_markers(self, gc, marker_path, marker_trans, path, trans, - rgbFace=None): + def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None): # docstring inherited _writeln(self.fh, r"\begin{pgfscope}") @@ -404,8 +403,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, r"\pgfsys@defobject{currentmarker}" r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords) self._print_pgf_path(None, marker_path, marker_trans) - self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, - fill=rgbFace is not None) + self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, fill=rgbFace is not None) _writeln(self.fh, r"}") maxcoord = 16383 / 72.27 * self.dpi # Max dimensions in LaTeX. @@ -429,8 +427,7 @@ def draw_path(self, gc, path, transform, rgbFace=None): self._print_pgf_clip(gc) self._print_pgf_path_styles(gc, rgbFace) self._print_pgf_path(gc, path, transform, rgbFace) - self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, - fill=rgbFace is not None) + self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, fill=rgbFace is not None) _writeln(self.fh, r"\end{pgfscope}") # if present, draw pattern on top @@ -453,6 +450,8 @@ 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) + 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}") @@ -464,8 +463,7 @@ def draw_path(self, gc, path, transform, rgbFace=None): xmin, xmax = f * xmin, f * xmax ymin, ymax = f * ymin, f * ymax repx, repy = math.ceil(xmax - xmin), math.ceil(ymax - ymin) - _writeln(self.fh, - r"\pgfsys@transformshift{%fin}{%fin}" % (xmin, ymin)) + _writeln(self.fh, r"\pgfsys@transformshift{%fin}{%fin}" % (xmin, ymin)) for iy in range(repy): for ix in range(repx): _writeln(self.fh, r"\pgfsys@useobject{currentpattern}{}") 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..31d9ac9ed7f0 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -9,10 +9,11 @@ import matplotlib as mpl import matplotlib.pyplot as plt +from matplotlib.backends.backend_pgf import FigureCanvasPgf, PdfPages +from matplotlib.backends.backend_pdf import FigureCanvasPdf 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.testing.decorators import ( _image_directories, check_figures_equal, image_comparison) from matplotlib.testing._markers import ( @@ -400,3 +401,18 @@ 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') +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='/') + error = None + try: + compare_figure('hatch_linewidth.pdf') + finally: + # Restore backend to not mess up other tests + mpl.backend_bases.register_backend('pdf', FigureCanvasPdf)