8000 Annotation: always use FancyBboxPatch instead of bbox_artist · matplotlib/matplotlib@c4d8f0d · GitHub
[go: up one dir, main page]

Skip to content

Commit c4d8f0d

Browse files
committed
Annotation: always use FancyBboxPatch instead of bbox_artist
1 parent c90469b commit c4d8f0d

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

lib/matplotlib/text.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from matplotlib.cbook import is_string_like, maxdict
2020
from matplotlib import docstring
2121
from matplotlib.font_manager import FontProperties
22-
from matplotlib.patches import bbox_artist, YAArrow, FancyBboxPatch
22+
from matplotlib.patches import YAArrow, FancyBboxPatch
2323
from matplotlib.patches import FancyArrowPatch, Rectangle
2424
import matplotlib.transforms as mtransforms
2525
from matplotlib.transforms import Affine2D, Bbox, Transform
@@ -446,25 +446,19 @@ def _get_layout(self, renderer):
446446
def set_bbox(self, rectprops):
447447
"""
448448
Draw a bounding box around self. rectprops are any settable
449-
properties for a rectangle, e.g., facecolor='red', alpha=0.5.
449+
properties for a FancyBboxPatch, e.g., facecolor='red', alpha=0.5.
450450
451451
t.set_bbox(dict(facecolor='red', alpha=0.5))
452452
453-
If rectprops has "boxstyle" key. A FancyBboxPatch
454-
is initialized with rectprops and will be drawn. The mutation
455-
scale of the FancyBboxPath is set to the fontsize.
453+
The default boxstyle is 'square'. The mutation
454+
scale of the FancyBboxPatch is set to the fontsize.
456455
457-
ACCEPTS: rectangle prop dict
456+
ACCEPTS: FancyBboxPatch prop dict
458457
"""
459458

460-
# The self._bbox_patch object is created only if rectprops has
461-
# boxstyle key. Otherwise, self._bbox will be set to the
462-
# rectprops and the bbox will be drawn using bbox_artist
463-
# function. This is to keep the backward compatibility.
464-
465-
if rectprops is not None and "boxstyle" in rectprops:
459+
if rectprops is not None:
466460
props = rectprops.copy()
467-
boxstyle = props.pop("boxstyle")
461+
boxstyle = props.pop("boxstyle", "square")
468462
bbox_transmuter = props.pop("bbox_transmuter", None)
469463

470464
self._bbox_patch = FancyBboxPatch(
@@ -474,10 +468,8 @@ def set_bbox(self, rectprops):
474468
bbox_transmuter=bbox_transmuter,
475469
transform=mtransforms.IdentityTransform(),
476470
**props)
477-
self._bbox = None
478471
else:
479472
self._bbox_patch = None
480-
self._bbox = rectprops
481473

482474
self._update_clip_properties()
483475

@@ -519,7 +511,7 @@ def update_bbox_position_size(self, renderer):
519511
def _draw_bbox(self, renderer, posx, posy):
520512

521513
""" Update the location and the size of the bbox
522-
(FancyBoxPatch), and draw
514+
(FancyBboxPatch), and draw
523515
"""
524516

525517
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
@@ -537,8 +529,6 @@ def _update_clip_properties(self):
537529
clip_path=self._clippath,
538530
clip_on=self._clipon)
539531

540-
if self._bbox:
541< 10000 /td>-
bbox = self._bbox.update(clipprops)
542532
if self._bbox_patch:
543533
bbox = self._bbox_patch.update(clipprops)
544534

@@ -622,8 +612,6 @@ def draw(self, renderer):
622612
gc.set_url(self._url)
623613
self._set_gc_clip(gc)
624614

625-
if self._bbox:
626-
bbox_artist(self, renderer, self._bbox)
627615
angle = self.get_rotation()
628616

629617
for line, wh, x, y in info:
@@ -825,10 +813,10 @@ def set_backgroundcolor(self, color):
825813
826814
ACCEPTS: any matplotlib color
827815
"""
828-
if self._bbox is None:
829-
self._bbox = dict(facecolor=color, edgecolor=color)
816+
if self._bbox_patch is None:
817+
self.set_bbox = dict(facecolor=color, edgecolor=color)
830818
else:
831-
self._bbox.update(dict(facecolor=color))
819+
self._bbox_patch.update(dict(facecolor=color))
832820

833821
self._update_clip_properties()
834822

@@ -1985,13 +1973,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
19851973
if self._bbox_patch:
19861974
self.arrow_patch.set_patchA(self._bbox_patch)
19871975
else:
1988-
props = self._bbox
1989-
if props is None:
1990-
props = {}
1991-
# don't want to alter the pad externally
1992-
props = props.copy()
1993-
pad = props.pop('pad', 4)
1994-
pad = renderer.points_to_pixels(pad)
1976+
pad = renderer.points_to_pixels(4)
19951977
if self.get_text().strip() == "":
19961978
self.arrow_patch.set_patchA(None)
19971979
return
@@ -2008,12 +1990,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
20081990
)
20091991
r.set_transform(mtransforms.IdentityTransform())
20101992
r.set_clip_on(False)
2011-
r.update(props)
20121993

20131994
self.arrow_patch.set_patchA(r)
20141995

20151996
else:
2016-
1997+
# using YAArrow
20171998
# pick the x,y corner of the text bbox closest to point
20181999
# annotated
20192000
dsu = [(abs(val - x0), val) for val in (l, r, xc)]

0 commit comments

Comments
 (0)
0