Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9d933bc

Browse filesBrowse files
committed
Annotation: always use FancyBboxPatch instead of bbox_artist
1 parent f37e6ef commit 9d933bc
Copy full SHA for 9d933bc

File tree

Expand file treeCollapse file tree

1 file changed

+13
-32
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-32
lines changed

‎lib/matplotlib/text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+13-32Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from matplotlib.cbook import is_string_like, maxdict
2222
from matplotlib import docstring
2323
from matplotlib.font_manager import FontProperties
24-
from matplotlib.patches import bbox_artist, YAArrow, FancyBboxPatch
24+
from matplotlib.patches import YAArrow, FancyBboxPatch
2525
from matplotlib.patches import FancyArrowPatch, Rectangle
2626
import matplotlib.transforms as mtransforms
2727
from matplotlib.transforms import Affine2D, Bbox, Transform
@@ -469,25 +469,19 @@ def _get_layout(self, renderer):
469469
def set_bbox(self, rectprops):
470470
"""
471471
Draw a bounding box around self. rectprops are any settable
472-
properties for a rectangle, e.g., facecolor='red', alpha=0.5.
472+
properties for a FancyBboxPatch, e.g., facecolor='red', alpha=0.5.
473473
474474
t.set_bbox(dict(facecolor='red', alpha=0.5))
475475
476-
If rectprops has "boxstyle" key. A FancyBboxPatch
477-
is initialized with rectprops and will be drawn. The mutation
478-
scale of the FancyBboxPath is set to the fontsize.
476+
The default boxstyle is 'square'. The mutation
477+
scale of the FancyBboxPatch is set to the fontsize.
479478
480-
ACCEPTS: rectangle prop dict
479+
ACCEPTS: FancyBboxPatch prop dict
481480
"""
482481

483-
# The self._bbox_patch object is created only if rectprops has
484-
# boxstyle key. Otherwise, self._bbox will be set to the
485-
# rectprops and the bbox will be drawn using bbox_artist
486-
# function. This is to keep the backward compatibility.
487-
488-
if rectprops is not None and "boxstyle" in rectprops:
482+
if rectprops is not None:
489483
props = rectprops.copy()
490-
boxstyle = props.pop("boxstyle")
484+
boxstyle = props.pop("boxstyle", "square")
491485
bbox_transmuter = props.pop("bbox_transmuter", None)
492486

493487
self._bbox_patch = FancyBboxPatch(
@@ -497,10 +491,8 @@ def set_bbox(self, rectprops):
497491
bbox_transmuter=bbox_transmuter,
498492
transform=mtransforms.IdentityTransform(),
499493
**props)
500-
self._bbox = None
501494
else:
502495
self._bbox_patch = None
503-
self._bbox = rectprops
504496

505497
self._update_clip_properties()
506498

@@ -542,7 +534,7 @@ def update_bbox_position_size(self, renderer):
542534
def _draw_bbox(self, renderer, posx, posy):
543535

544536
""" Update the location and the size of the bbox
545-
(FancyBoxPatch), and draw
537+
(FancyBboxPatch), and draw
546538
"""
547539

548540
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
@@ -560,8 +552,6 @@ def _update_clip_properties(self):
560552
clip_path=self._clippath,
561553
clip_on=self._clipon)
562554

563-
if self._bbox:
564-
bbox = self._bbox.update(clipprops)
565555
if self._bbox_patch:
566556
bbox = self._bbox_patch.update(clipprops)
567557

@@ -756,8 +746,6 @@ def draw(self, renderer):
756746
gc.set_url(textobj._url)
757747
textobj._set_gc_clip(gc)
758748

759-
if textobj._bbox:
760-
bbox_artist(textobj, renderer, textobj._bbox)
761749
angle = textobj.get_rotation()
762750

763751
for line, wh, x, y in info:
@@ -959,10 +947,10 @@ def set_backgroundcolor(self, color):
959947
960948
ACCEPTS: any matplotlib color
961949
"""
962-
if self._bbox is None:
963-
self._bbox = dict(facecolor=color, edgecolor=color)
950+
if self._bbox_patch is None:
951+
self.set_bbox = dict(facecolor=color, edgecolor=color)
964952
else:
965-
self._bbox.update(dict(facecolor=color))
953+
self._bbox_patch.update(dict(facecolor=color))
966954

967955
self._update_clip_properties()
968956
self.stale = True
@@ -2147,13 +2135,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
21472135
if self._bbox_patch:
21482136
self.arrow_patch.set_patchA(self._bbox_patch)
21492137
else:
2150-
props = self._bbox
2151-
if props is None:
2152-
props = {}
2153-
# don't want to alter the pad externally
2154-
props = props.copy()
2155-
pad = props.pop('pad', 4)
2156-
pad = renderer.points_to_pixels(pad)
2138+
pad = renderer.points_to_pixels(4)
21572139
if self.get_text().strip() == "":
21582140
self.arrow_patch.set_patchA(None)
21592141
return
@@ -2170,12 +2152,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
21702152
)
21712153
r.set_transform(mtransforms.IdentityTransform())
21722154
r.set_clip_on(False)
2173-
r.update(props)
21742155

21752156
self.arrow_patch.set_patchA(r)
21762157

21772158
else:
2178-
2159+
# using YAArrow
21792160
# pick the x,y corner of the text bbox closest to point
21802161
# annotated
21812162
dsu = [(abs(val - x0), val) for val in (l, r, xc)]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.