@@ -421,7 +421,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
421
421
bl , tr = marker_path .get_extents (marker_trans ).get_points ()
422
422
coords = bl [0 ] * f , bl [1 ] * f , tr [0 ] * f , tr [1 ] * f
423
423
writeln (self .fh , r"\pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords )
424
- self ._print_pgf_path (marker_path , marker_trans )
424
+ self ._print_pgf_path (None , marker_path , marker_trans )
425
425
self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
426
426
fill = rgbFace is not None )
427
427
writeln (self .fh , r"}" )
@@ -441,7 +441,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
441
441
# draw the path
442
442
self ._print_pgf_clip (gc )
443
443
self ._print_pgf_path_styles (gc , rgbFace )
444
- self ._print_pgf_path (path , transform )
444
+ self ._print_pgf_path (gc , path , transform )
445
445
self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
446
446
fill = rgbFace is not None )
447
447
writeln (self .fh , r"\end{pgfscope}" )
@@ -452,7 +452,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
452
452
453
453
# combine clip and path for clipping
454
454
self ._print_pgf_clip (gc )
455
- self ._print_pgf_path (path , transform )
455
+ self ._print_pgf_path (gc , path , transform )
456
456
writeln (self .fh , r"\pgfusepath{clip}" )
457
457
458
458
# build pattern definition
@@ -461,7 +461,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
461
461
writeln (self .fh , r"\pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}" )
462
462
writeln (self .fh , r"\pgfusepath{clip}" )
463
463
scale = mpl .transforms .Affine2D ().scale (self .dpi )
464
- self ._print_pgf_path (gc .get_hatch_path (), scale )
464
+ self ._print_pgf_path (None , gc .get_hatch_path (), scale )
465
465
self ._pgf_path_draw (stroke = True )
466
466
writeln (self .fh , r"\end{pgfscope}" )
467
467
writeln (self .fh , r"}" )
@@ -495,7 +495,7 @@ def _print_pgf_clip(self, gc):
495
495
# check for clip path
496
496
clippath , clippath_trans = gc .get_clip_path ()
497
497
if clippath is not None :
498
- self ._print_pgf_path (clippath , clippath_trans )
498
+ self ._print_pgf_path (gc , clippath , clippath_trans )
499
499
writeln (self .fh , r"\pgfusepath{clip}" )
500
500
501
501
def _print_pgf_path_styles (self , gc , rgbFace ):
@@ -543,10 +543,17 @@ def _print_pgf_path_styles(self, gc, rgbFace):
543
543
dash_str += r"}{%fpt}" % dash_offset
544
544
writeln (self .fh , dash_str )
545
545
546
- def _print_pgf_path (self , path , transform ):
546
+ def _print_pgf_path (self , gc , path , transform ):
547
547
f = 1. / self .dpi
548
+ # check for clip box
549
+ bbox = gc .get_clip_rectangle () if gc else None
550
+ if bbox :
551
+ p1 , p2 = bbox .get_points ()
552
+ clip = (p1 [0 ], p1 [1 ], p2 [0 ], p2 [1 ])
553
+ else :
554
+ clip = None
548
555
# build path
549
- for points , code in path .iter_segments (transform ):
556
+ for points , code in path .iter_segments (transform , clip = clip ):
550
557
if code == Path .MOVETO :
551
558
x , y = tuple (points )
552
559
writeln (self .fh , r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
0 commit comments