8000 fixed Text.set_backgroundcolor · matplotlib/matplotlib@8c34b22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c34b22

Browse files
committed
fixed Text.set_backgroundcolor
svn path=/trunk/matplotlib/; revision=2958
1 parent b43356c commit 8c34b22

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/matplotlib/axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,13 @@ def text(self, x, y, s, fontdict=None,
18861886
)
18871887
18881888
1889+
You can put a rectangular box around the text instance (eg to
1890+
set a background color) by using the keyword bbox. bbox is a
1891+
dictionary of matplotlib.patches.Rectangle properties (see help
1892+
for Rectangle for a list of these). For example
1893+
1894+
text(x, y, s, bbox=dict(facecolor='red', alpha=0.5))
1895+
18891896
Valid kwargs are Text properties
18901897
%(Text)s
18911898
"""

lib/matplotlib/text.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ def _get_layout(self, renderer):
308308
def set_bbox(self, rectprops):
309309
"""
310310
Draw a bounding box around self. rect props are any settable
311-
properties for a rectangle, eg color='r', alpha=0.5
311+
properties for a rectangle, eg facecolor='red', alpha=0.5.
312+
313+
t.set_bbox(dict(facecolor='red', alpha=0.5))
312314
313315
ACCEPTS: rectangle prop dict plus key 'pad' which is a pad in points
314316
"""
@@ -525,11 +527,15 @@ def get_rotation_matrix(self, x0, y0):
525527

526528
def set_backgroundcolor(self, color):
527529
"""
528-
Set the background color of the text
530+
Set the background color of the text by updating the bbox (see set_bbox for more info)
529531
530532
ACCEPTS: any matplotlib color
531533
"""
532-
self._backgroundcolor = color
534+
if self._bbox is None:
535+
self._bbox = dict(facecolor=color, edgecolor=color)
536+
else:
537+
self._bbox.update(dict(facecolor=color))
538+
533539

534540

535541
def set_color(self, color):

0 commit comments

Comments
 (0)
0