From 54ada609a12c4dd7ee5aed32f238f325b7cc627a Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 17 Dec 2018 15:11:23 +0100 Subject: [PATCH] Create Texts directly with all kwargs --- lib/matplotlib/axes/_axes.py | 23 ++++++++++++----------- lib/matplotlib/text.py | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 8bb104487702..f4ce4dded35d 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -699,11 +699,17 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs): >>> text(x, y, s, bbox=dict(facecolor='red', alpha=0.5)) """ - default = { + if fontdict is None: + fontdict = {} + + effective_kwargs = { 'verticalalignment': 'baseline', 'horizontalalignment': 'left', 'transform': self.transData, - 'clip_on': False} + 'clip_on': False, + **fontdict, + **kwargs, + } # At some point if we feel confident that TextWithDash # is robust as a drop-in replacement for Text and that @@ -711,17 +717,12 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs): # isn't too significant, it may make sense to eliminate # the withdash kwarg and simply delegate whether there's # a dash to TextWithDash and dashlength. + if withdash: - t = mtext.TextWithDash( - x=x, y=y, text=s) + t = mtext.TextWithDash(x, y, text=s) else: - t = mtext.Text( - x=x, y=y, text=s) - - t.update(default) - if fontdict is not None: - t.update(fontdict) - t.update(kwargs) + t = mtext.Text(x, y, text=s) + t.update(effective_kwargs) t.set_clip_path(self.patch) self._add_text(t) diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 7cd48ef06b6a..c86292d9ebe5 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1319,7 +1319,8 @@ def __init__(self, multialignment=multialignment, fontproperties=fontproperties, rotation=rotation, - linespacing=linespacing) + linespacing=linespacing, + ) # The position (x,y) values for text and dashline # are bogus as given in the instantiation; they will
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: