Skip to content

Commit cb9fcd6

Browse files
authored
Merge pull request matplotlib#29875 from timhoffm/doc-text-bbox
2 parents 4fa258a + 32527c5 commit cb9fcd6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/matplotlib/text.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,21 @@ def _get_layout(self, renderer):
516516

517517
def set_bbox(self, rectprops):
518518
"""
519-
Draw a bounding box around self.
519+
Draw a box behind/around the text.
520+
521+
This can be used to set a background and/or a frame around the text.
522+
It's realized through a `.FancyBboxPatch` behind the text (see also
523+
`.Text.get_bbox_patch`). The bbox patch is None by default and only
524+
created when needed.
520525
521526
Parameters
522527
----------
523-
rectprops : dict with properties for `.patches.FancyBboxPatch`
528+
rectprops : dict with properties for `.FancyBboxPatch` or None
524529
The default boxstyle is 'square'. The mutation
525530
scale of the `.patches.FancyBboxPatch` is set to the fontsize.
526531
532+
Pass ``None`` to remove the bbox patch completely.
533+
527534
Examples
528535
--------
529536
::
@@ -558,6 +565,8 @@ def get_bbox_patch(self):
558565
"""
559566
Return the bbox Patch, or None if the `.patches.FancyBboxPatch`
560567
is not made.
568+
569+
For more details see `.Text.set_bbox`.
561570
"""
562571
return self._bbox_patch
563572

@@ -981,7 +990,10 @@ def get_window_extent(self, renderer=None, dpi=None):
981990

982991
def set_backgroundcolor(self, color):
983992
"""
984-
Set the background color of the text by updating the bbox.
993+
Set the background color of the text.
994+
995+
This is realized through the bbox (see `.set_bbox`),
996+
creating the bbox patch if needed.
985997
986998
Parameters
987999
----------

lib/matplotlib/text.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Text(Artist):
4848
def get_transform_rotates_text(self) -> bool: ...
4949
def set_rotation_mode(self, m: None | Literal["default", "anchor", "xtick", "ytick"]) -> None: ...
5050
def get_rotation_mode(self) -> Literal["default", "anchor", "xtick", "ytick"]: ...
51-
def set_bbox(self, rectprops: dict[str, Any]) -> None: ...
51+
def set_bbox(self, rectprops: dict[str, Any] | None) -> None: ...
5252
def get_bbox_patch(self) -> None | FancyBboxPatch: ...
5353
def update_bbox_position_size(self, renderer: RendererBase) -> None: ...
5454
def get_wrap(self) -> bool: ...

0 commit comments

Comments
 (0)