10000 Try restoring linewidth · matplotlib/matplotlib@04232ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 04232ab

Browse files
committed
Try restoring linewidth
1 parent 27f171c commit 04232ab

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,17 @@ def draw_path(self, gc, path, transform, rgbFace=None):
453453
r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}")
454454
_writeln(self.fh, r"\pgfusepath{clip}")
455455
scale = mpl.transforms.Affine2D().scale(self.dpi)
456+
# Store default PGF line width
457+
_writeln(self.fh, r"\newlength{\defaultpgflinewidth}")
458+
_writeln(self.fh,
459+
r"\setlength{\defaultpgflinewidth}{\pgflinewidth}")
456460
lw = (mpl.rcParams["hatch.linewidth"]
457461
* mpl_pt_to_in * latex_in_to_pt)
458462
_writeln(self.fh, r"\pgfsetlinewidth{%fpt}" % lw)
459463
self._print_pgf_path(None, gc.get_hatch_path(), scale)
460464
self._pgf_path_draw(stroke=True)
465+
# Restore default PGF line width
466+
_writeln(self.fh, r"\pgfsetlinewidth{\defaultpgflinewidth}")
461467
_writeln(self.fh, r"\end{pgfscope}")
462468
_writeln(self.fh, r"}")
463469
# repeat pattern, filling the bounding rect of the path

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 18 additions & 6 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
import matplotlib as mpl
1111
import matplotlib.pyplot as plt
12-
from matplotlib.testing import _has_tex_package, _check_for_pgf
13-
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1412
from matplotlib.backends.backend_pgf import FigureCanvasPgf, PdfPages
13+
from matplotlib.backends.backend_pdf import FigureCanvasPdf
14+
from matplotlib.testing import _has_tex_package, _check_for_pgf
15+
from matplotlib.testing.compare import compare_images
16+
from matplotlib.testing.exceptions import ImageComparisonFailure
1517
from matplotlib.testing.decorators import (
1618
_image_directories, check_figures_equal, image_comparison)
1719
from matplotlib.testing._markers import (
@@ -377,7 +379,6 @@ def test_sketch_params():
377379
assert baseline in buf
378380

379381

380-
<<<<<<< HEAD
381382
# test to make sure that the document font size is set consistently (see #26892)
382383
@needs_pgf_xelatex
383384
@pytest.mark.skipif(
@@ -400,13 +401,24 @@ def test_document_font_size():
400401
label=r'\normalsize the document font size is \the\fontdimen6\font'
401402
)
402403
plt.legend()
403-
=======
404+
405+
404406
@needs_pgf_xelatex
405407
@pytest.mark.backend('pgf')
406-
@image_comparison(['hatch_linewidth'], extensions=['pdf'])
407408
def test_pgf_hatch_linewidth():
408409
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
409410
mpl.rcParams['hatch.linewidth'] = 0.1
410411

411412
plt.bar(1, 1, color='white', edgecolor='black', hatch='/')
412-
>>>>>>> 7cbcd44f9a (Fix hatch linewidth in PGF)
413+
error = None
414+
try:
415+
compare_figure('hatch_linewidth.pdf')
416+
except ImageComparisonFailure as e:
417+
# Store if error
418+
error = e
419+
# Restore backend to not mess up other tests
420+
mpl.backend_bases.register_backend('pdf', FigureCanvasPdf)
421+
422+
if error is not None:
423+
# Re-raise stored error
424+
raise error

0 commit comments

Comments
 (0)
0