Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d44eab

Browse files
oscargusanntzer
andcommitted
Fix hatch linewidth in PGF
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parentcf6069a commit1d44eab

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

‎lib/matplotlib/backends/backend_pgf.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ def __init__(self, figure, fh):
384384
self.figure=figure
385385
self.image_counter=0
386386

387-
defdraw_markers(self,gc,marker_path,marker_trans,path,trans,
388-
rgbFace=None):
387+
defdraw_markers(self,gc,marker_path,marker_trans,path,trans,rgbFace=None):
389388
# docstring inherited
390389

391390
_writeln(self.fh,r"\begin{pgfscope}")
@@ -404,8 +403,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans,
404403
r"\pgfsys@defobject{currentmarker}"
405404
r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{"%coords)
406405
self._print_pgf_path(None,marker_path,marker_trans)
407-
self._pgf_path_draw(stroke=gc.get_linewidth()!=0.0,
408-
fill=rgbFaceisnotNone)
406+
self._pgf_path_draw(stroke=gc.get_linewidth()!=0.0,fill=rgbFaceisnotNone)
409407
_writeln(self.fh,r"}")
410408

411409
maxcoord=16383/72.27*self.dpi# Max dimensions in LaTeX.
@@ -429,8 +427,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
429427
self._print_pgf_clip(gc)
430428
self._print_pgf_path_styles(gc,rgbFace)
431429
self._print_pgf_path(gc,path,transform,rgbFace)
432-
self._pgf_path_draw(stroke=gc.get_linewidth()!=0.0,
433-
fill=rgbFaceisnotNone)
430+
self._pgf_path_draw(stroke=gc.get_linewidth()!=0.0,fill=rgbFaceisnotNone)
434431
_writeln(self.fh,r"\end{pgfscope}")
435432

436433
# if present, draw pattern on top
@@ -453,6 +450,8 @@ def draw_path(self, gc, path, transform, rgbFace=None):
453450
r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}")
454451
_writeln(self.fh,r"\pgfusepath{clip}")
455452
scale=mpl.transforms.Affine2D().scale(self.dpi)
453+
lw= (mpl.rcParams["hatch.linewidth"]*mpl_pt_to_in*latex_in_to_pt)
454+
_writeln(self.fh,r"\pgfsetlinewidth{%fpt}"%lw)
456455
self._print_pgf_path(None,gc.get_hatch_path(),scale)
457456
self._pgf_path_draw(stroke=True)
458457
_writeln(self.fh,r"\end{pgfscope}")
@@ -464,8 +463,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
464463
xmin,xmax=f*xmin,f*xmax
465464
ymin,ymax=f*ymin,f*ymax
466465
repx,repy=math.ceil(xmax-xmin),math.ceil(ymax-ymin)
467-
_writeln(self.fh,
468-
r"\pgfsys@transformshift{%fin}{%fin}"% (xmin,ymin))
466+
_writeln(self.fh,r"\pgfsys@transformshift{%fin}{%fin}"% (xmin,ymin))
469467
foriyinrange(repy):
470468
forixinrange(repx):
471469
_writeln(self.fh,r"\pgfsys@useobject{currentpattern}{}")
Binary file not shown.

‎lib/matplotlib/tests/test_backend_pgf.py

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

1010
importmatplotlibasmpl
1111
importmatplotlib.pyplotasplt
12+
frommatplotlib.backends.backend_pgfimportFigureCanvasPgf,PdfPages
13+
frommatplotlib.backends.backend_pdfimportFigureCanvasPdf
1214
frommatplotlib.testingimport_has_tex_package,_check_for_pgf
13-
frommatplotlib.testing.exceptionsimportImageComparisonFailure
1415
frommatplotlib.testing.compareimportcompare_images
15-
frommatplotlib.backends.backend_pgfimportPdfPages
16+
frommatplotlib.testing.exceptionsimportImageComparisonFailure
1617
frommatplotlib.testing.decoratorsimport (
1718
_image_directories,check_figures_equal,image_comparison)
1819
frommatplotlib.testing._markersimport (
@@ -400,3 +401,18 @@ def test_document_font_size():
400401
label=r'\normalsize the document font size is \the\fontdimen6\font'
401402
)
402403
plt.legend()
404+
405+
406+
@needs_pgf_xelatex
407+
@pytest.mark.backend('pgf')
408+
deftest_pgf_hatch_linewidth():
409+
mpl.backend_bases.register_backend('pdf',FigureCanvasPgf)
410+
mpl.rcParams['hatch.linewidth']=0.1
411+
412+
plt.bar(1,1,color='white',edgecolor='black',hatch='/')
413+
error=None
414+
try:
415+
compare_figure('hatch_linewidth.pdf')
416+
finally:
417+
# Restore backend to not mess up other tests
418+
mpl.backend_bases.register_backend('pdf',FigureCanvasPdf)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp