Draw a box behind/around the text. This can be used to set a background and/or a frame around the text. It's realized through a `.FancyBboxPatch` behind the text (see also `.Text.get_bbox_patch`). The bbox patch is None by default and only created when neede
(self, rectprops)
| 601 | return bbox_rot, list(zip(lines, wads, xys)), (xy_corner, size_horiz) |
| 602 | |
| 603 | def set_bbox(self, rectprops): |
| 604 | """ |
| 605 | Draw a box behind/around the text. |
| 606 | |
| 607 | This can be used to set a background and/or a frame around the text. |
| 608 | It's realized through a `.FancyBboxPatch` behind the text (see also |
| 609 | `.Text.get_bbox_patch`). The bbox patch is None by default and only |
| 610 | created when needed. |
| 611 | |
| 612 | Parameters |
| 613 | ---------- |
| 614 | rectprops : dict with properties for `.FancyBboxPatch` or None |
| 615 | The default boxstyle is 'square'. The mutation |
| 616 | scale of the `.patches.FancyBboxPatch` is set to the fontsize. |
| 617 | |
| 618 | Pass ``None`` to remove the bbox patch completely. |
| 619 | |
| 620 | Examples |
| 621 | -------- |
| 622 | :: |
| 623 | |
| 624 | t.set_bbox(dict(facecolor='red', alpha=0.5)) |
| 625 | """ |
| 626 | |
| 627 | if rectprops is not None: |
| 628 | props = rectprops.copy() |
| 629 | boxstyle = props.pop("boxstyle", None) |
| 630 | pad = props.pop("pad", None) |
| 631 | if boxstyle is None: |
| 632 | boxstyle = "square" |
| 633 | if pad is None: |
| 634 | pad = 4 # points |
| 635 | pad /= self.get_size() # to fraction of font size |
| 636 | else: |
| 637 | if pad is None: |
| 638 | pad = 0.3 |
| 639 | # boxstyle could be a callable or a string |
| 640 | if isinstance(boxstyle, str) and "pad" not in boxstyle: |
| 641 | boxstyle += ",pad=%0.2f" % pad |
| 642 | self._bbox_patch = FancyBboxPatch( |
| 643 | (0, 0), 1, 1, |
| 644 | boxstyle=boxstyle, transform=IdentityTransform(), **props) |
| 645 | else: |
| 646 | self._bbox_patch = None |
| 647 | |
| 648 | self._update_clip_properties() |
| 649 | |
| 650 | def get_bbox_patch(self): |
| 651 | """ |