Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54ada60

Browse files
committed
Create Texts directly with all kwargs
1 parent dba2d7b commit 54ada60

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -699,29 +699,30 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
699699
700700
>>> text(x, y, s, bbox=dict(facecolor='red', alpha=0.5))
701701
"""
702-
default = {
702+
if fontdict is None:
703+
fontdict = {}
704+
705+
effective_kwargs = {
703706
'verticalalignment': 'baseline',
704707
'horizontalalignment': 'left',
705708
'transform': self.transData,
706-
'clip_on': False}
709+
'clip_on': False,
710+
**fontdict,
711+
**kwargs,
712+
}
707713

708714
# At some point if we feel confident that TextWithDash
709715
# is robust as a drop-in replacement for Text and that
710716
# the performance impact of the heavier-weight class
711717
# isn't too significant, it may make sense to eliminate
712718
# the withdash kwarg and simply delegate whether there's
713719
# a dash to TextWithDash and dashlength.
720+
714721
if withdash:
715-
t = mtext.TextWithDash(
716-
x=x, y=y, text=s)
722+
t = mtext.TextWithDash(x, y, text=s)
717723
else:
718-
t = mtext.Text(
719-
x=x, y=y, text=s)
720-
721-
t.update(default)
722-
if fontdict is not None:
723-
t.update(fontdict)
724-
t.update(kwargs)
724+
t = mtext.Text(x, y, text=s)
725+
t.update(effective_kwargs)
725726

726727
t.set_clip_path(self.patch)
727728
self._add_text(t)

lib/matplotlib/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,8 @@ def __init__(self,
13191319
multialignment=multialignment,
13201320
fontproperties=fontproperties,
13211321
rotation=rotation,
1322-
linespacing=linespacing)
1322+
linespacing=linespacing,
1323+
)
13231324

13241325
# The position (x,y) values for text and dashline
13251326
# are bogus as given in the instantiation; they will

0 commit comments

Comments
 (0)