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 54ada60

Browse filesBrowse files
committed
Create Texts directly with all kwargs
1 parent dba2d7b commit 54ada60
Copy full SHA for 54ada60

File tree

Expand file treeCollapse file tree

2 files changed

+14
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-12
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+12-11Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+2-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.