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

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 fb7f90c

Browse files
committed
Annotation: always use FancyBboxPatch instead of bbox_artist
1 parent 199952b commit fb7f90c

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-
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:
@@ -823,10 +811,10 @@ def set_backgroundcolor(self, color):
823811
824812
ACCEPTS: any matplotlib color
825813
"""
826-
if self._bbox is None:
827-
self._bbox = dict(facecolor=color, edgecolor=color)
814+
if self._bbox_patch is None:
815+
self.set_bbox = dict(facecolor=color, edgecolor=color)
828816
else:
829-
self._bbox.update(dict(facecolor=color))
817+
self._bbox_patch.update(dict(facecolor=color))
830818

831819
self._update_clip_properties()
832820

@@ -1983,13 +1971,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
19831971
if self._bbox_patch:
19841972
self.arrow_patch.set_patchA(self._bbox_patch)
19851973
else:
1986-
props = self._bbox
1987-
if props is None:
1988-
props = {}
1989-
# don't want to alter the pad externally
1990-
props = props.copy()
1991-
pad = props.pop('pad', 4)
1992-
pad = renderer.points_to_pixels(pad)
1974+
pad = renderer.points_to_pixels(4)
19931975
if self.get_text().strip() == "":
19941976
self.arrow_patch.set_patchA(None)
19951977
return
@@ -2006,12 +1988,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
20061988
)
20071989
r.set_transform(mtransforms.IdentityTransform())
20081990
r.set_clip_on(False)
2009-
r.update(props)
20101991

20111992
self.arrow_patch.set_patchA(r)
20121993

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

0 commit comments

Comments
 (0)
0