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

Skip to content

Commit 9821dc0

Browse files
committed
Make PDF and PS hatching origin the same as Agg's.
Agg uses top-left as origin, while PDF/PS use bottom-left. A vertical shift by the page height fixes that. See example in #4108.
1 parent f2853bd commit 9821dc0

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,9 @@ def writeHatches(self):
11711171
'PatternType': 1, 'PaintType': 1, 'TilingType': 1,
11721172
'BBox': [0, 0, sidelen, sidelen],
11731173
'XStep': sidelen, 'YStep': sidelen,
1174-
'Resources': res})
1174+
'Resources': res,
1175+
# Change origin to match Agg at top-left.
1176+
'Matrix': [1, 0, 0, 1, 0, self.height * 72]})
11751177

11761178
stroke_rgb, fill_rgb, path = hatch_style
11771179
self.output(stroke_rgb[0], stroke_rgb[1], stroke_rgb[2],

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def create_hatch(self, hatch):
305305
return self._hatches[hatch]
306306
name = 'H%d' % len(self._hatches)
307307
linewidth = rcParams['hatch.linewidth']
308+
pageheight = self.height * 72
308309
self._pswriter.write("""\
309310
<< /PatternType 1
310311
/PaintType 2
@@ -325,6 +326,7 @@ def create_hatch(self, hatch):
325326
} bind
326327
>>
327328
matrix
329+
0.0 %(pageheight)f translate
328330
makepattern
329331
/%(name)s exch def
330332
""" % locals())
23 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)