@@ -2179,7 +2179,7 @@ def _get_transform(self, transform):
21792179
21802180def _update_text (self , props ):
21812181 """
2182- Monkey patch that adds pseudo "border" properties to text objects
2182+ Monkey patch that adds pseudo "border" and "bbox" properties to text objects
21832183 without wrapping the entire class. We override update to facilitate
21842184 updating inset titles.
21852185 """
@@ -2201,6 +2201,20 @@ def _update_text(self, props):
22012201 'color' : facecolor ,
22022202 'path_effects' : [mpatheffects .Stroke (** kwargs ), mpatheffects .Normal ()],
22032203 })
2204+
2205+ bbox = props .pop ('bbox' , None )
2206+ bboxcolor = props .pop ('bboxcolor' , 'w' )
2207+ bboxstyle = props .pop ('bboxstyle' , 'round' )
2208+ bboxalpha = props .pop ('bboxalpha' , 0.5 )
2209+
2210+ if bbox :
2211+ self .set_bbox ({
2212+ 'facecolor' : bboxcolor ,
2213+ 'edgecolor' : 'black' ,
2214+ 'boxstyle' : bboxstyle ,
2215+ 'alpha' : bboxalpha ,
2216+ })
2217+
22042218 return type (self ).update (self , props )
22052219
22062220
@@ -2209,11 +2223,12 @@ def text_wrapper(
22092223 x = 0 , y = 0 , text = '' , transform = 'data' ,
22102224 family = None , fontfamily = None , fontname = None , fontsize = None , size = None ,
22112225 border = False , bordercolor = 'w' , borderwidth = 2 , borderinvert = False ,
2226+ bbox = False , bboxcolor = 'w' , bboxstyle = 'round' , bboxalpha = 0.5 ,
22122227 ** kwargs
22132228):
22142229 """
22152230 Enables specifying `tranform` with a string name and adds a feature for
2216- drawing borders around text.
2231+ drawing borders and bbox around text.
22172232
22182233 Note
22192234 ----
@@ -2248,7 +2263,14 @@ def text_wrapper(
22482263 The color of the text border. Default is ``'w'``.
22492264 borderinvert : bool, optional
22502265 If ``True``, the text and border colors are swapped.
2251-
2266+ bbox : bool, optional
2267+ Whether to draw bbox around text.
2268+ bboxcolor : color-spec, optional
2269+ The color of the text bbox. Default is ``'w'``.
2270+ bboxstyle : boxstyle, optional
2271+ The style of the bbox. Default is ``'round'``.
2272+ bboxalpha : float, optional
2273+ The alpha for the bbox. Default is ``'0.5'``.
22522274 Other parameters
22532275 ----------------
22542276 **kwargs
@@ -2287,6 +2309,10 @@ def text_wrapper(
22872309 'bordercolor' : bordercolor ,
22882310 'borderinvert' : borderinvert ,
22892311 'borderwidth' : borderwidth ,
2312+ 'bbox' : bbox ,
2313+ 'bboxcolor' : bboxcolor ,
2314+ 'bboxstyle' : bboxstyle ,
2315+ 'bboxalpha' : bboxalpha ,
22902316 })
22912317 return obj
22922318
0 commit comments