2424import matplotlib .transforms as mtransforms
2525import matplotlib .artist as martist
2626import matplotlib .text as mtext
27+ import matplotlib .path as mpath
2728import numpy as np
2829from matplotlib .transforms import Bbox , BboxBase , TransformedBbox
2930
@@ -569,14 +570,16 @@ class DrawingArea(OffsetBox):
569570 """
570571 The DrawingArea can contain any Artist as a child. The DrawingArea
571572 has a fixed width and height. The position of children relative to
572- the parent is fixed.
573+ the parent is fixed. The children can be clipped at the
574+ boundaries of the parent.
573575 """
574576
575577 def __init__ (self , width , height , xdescent = 0. ,
576- ydescent = 0. , clip = True ):
578+ ydescent = 0. , clip = False ):
577579 """
578580 *width*, *height* : width and height of the container box.
579581 *xdescent*, *ydescent* : descent of the box in x- and y-direction.
582+ *clip* : Whether to clip the children
580583 """
581584
582585 super (DrawingArea , self ).__init__ ()
@@ -585,6 +588,7 @@ def __init__(self, width, height, xdescent=0.,
585588 self .height = height
586589 self .xdescent = xdescent
587590 self .ydescent = ydescent
591+ self ._clip_children = clip
588592
589593 self .offset_transform = mtransforms .Affine2D ()
590594 self .offset_transform .clear ()
@@ -656,7 +660,17 @@ def draw(self, renderer):
656660 self .dpi_transform .clear ()
657661 self .dpi_transform .scale (dpi_cor , dpi_cor )
658662
663+ # At this point the DrawingArea has a transform
664+ # to the display space so the path created is
665+ # good for clipping children
666+ tpath = mtransforms .TransformedPath (
667+ mpath .Path ([[0 , 0 ], [0 , self .height ],
668+ [self .width , self .height ],
669+ [self .width , 0 ]]),
670+ self .get_transform ())
659671 for c in self ._children :
672+ if self ._clip_children and not (c .clipbox or c ._clippath ):
673+ c .set_clip_path (tpath )
660674 c .draw (renderer )
661675
662676 bbox_artist (self , renderer , fill = False , props = dict (pad = 0. ))
0 commit comments