@@ -421,7 +421,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
421421 bl , tr = marker_path .get_extents (marker_trans ).get_points ()
422422 coords = bl [0 ] * f , bl [1 ] * f , tr [0 ] * f , tr [1 ] * f
423423 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 )
425425 self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
426426 fill = rgbFace is not None )
427427 writeln (self .fh , r"}" )
@@ -441,7 +441,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
441441 # draw the path
442442 self ._print_pgf_clip (gc )
443443 self ._print_pgf_path_styles (gc , rgbFace )
444- self ._print_pgf_path (path , transform )
444+ self ._print_pgf_path (gc , path , transform )
445445 self ._pgf_path_draw (stroke = gc .get_linewidth () != 0.0 ,
446446 fill = rgbFace is not None )
447447 writeln (self .fh , r"\end{pgfscope}" )
@@ -452,7 +452,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
452452
453453 # combine clip and path for clipping
454454 self ._print_pgf_clip (gc )
455- self ._print_pgf_path (path , transform )
455+ self ._print_pgf_path (gc , path , transform )
456456 writeln (self .fh , r"\pgfusepath{clip}" )
457457
458458 # build pattern definition
@@ -461,7 +461,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
461461 writeln (self .fh , r"\pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}" )
462462 writeln (self .fh , r"\pgfusepath{clip}" )
463463 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 )
465465 self ._pgf_path_draw (stroke = True )
466466 writeln (self .fh , r"\end{pgfscope}" )
467467 writeln (self .fh , r"}" )
@@ -495,7 +495,7 @@ def _print_pgf_clip(self, gc):
495495 # check for clip path
496496 clippath , clippath_trans = gc .get_clip_path ()
497497 if clippath is not None :
498- self ._print_pgf_path (clippath , clippath_trans )
498+ self ._print_pgf_path (gc , clippath , clippath_trans )
499499 writeln (self .fh , r"\pgfusepath{clip}" )
500500
501501 def _print_pgf_path_styles (self , gc , rgbFace ):
@@ -543,10 +543,17 @@ def _print_pgf_path_styles(self, gc, rgbFace):
543543 dash_str += r"}{%fpt}" % dash_offset
544544 writeln (self .fh , dash_str )
545545
546- def _print_pgf_path (self , path , transform ):
546+ def _print_pgf_path (self , gc , path , transform ):
547547 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
548555 # build path
549- for points , code in path .iter_segments (transform ):
556+ for points , code in path .iter_segments (transform , clip = clip ):
550557 if code == Path .MOVETO :
551558 x , y = tuple (points )
552559 writeln (self .fh , r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" %
0 commit comments