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 3ad0bc5

Browse filesBrowse files
authored
Merge pull request #27728 from anntzer/suplabels_aliases
Simplify Figure._suplabels.
2 parents 0acaadc + fd4ea1d commit 3ad0bc5
Copy full SHA for 3ad0bc5

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+14
-21
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+10-17Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ def _suplabels(self, t, info, **kwargs):
281281
Additional kwargs are `matplotlib.text.Text` properties.
282282
"""
283283

284-
suplab = getattr(self, info['name'])
285-
286284
x = kwargs.pop('x', None)
287285
y = kwargs.pop('y', None)
288286
if info['name'] in ['_supxlabel', '_suptitle']:
@@ -294,29 +292,24 @@ def _suplabels(self, t, info, **kwargs):
294292
if y is None:
295293
y = info['y0']
296294

297-
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs:
298-
kwargs['horizontalalignment'] = info['ha']
299-
if 'verticalalignment' not in kwargs and 'va' not in kwargs:
300-
kwargs['verticalalignment'] = info['va']
301-
if 'rotation' not in kwargs:
302-
kwargs['rotation'] = info['rotation']
295+
kwargs = cbook.normalize_kwargs(kwargs, Text)
296+
kwargs.setdefault('horizontalalignment', info['ha'])
297+
kwargs.setdefault('verticalalignment', info['va'])
298+
kwargs.setdefault('rotation', info['rotation'])
303299

304300
if 'fontproperties' not in kwargs:
305-
if 'fontsize' not in kwargs and 'size' not in kwargs:
306-
kwargs['size'] = mpl.rcParams[info['size']]
307-
if 'fontweight' not in kwargs and 'weight' not in kwargs:
308-
kwargs['weight'] = mpl.rcParams[info['weight']]
301+
kwargs.setdefault('fontsize', mpl.rcParams[info['size']])
302+
kwargs.setdefault('fontweight', mpl.rcParams[info['weight']])
309303

310-
sup = self.text(x, y, t, **kwargs)
304+
suplab = getattr(self, info['name'])
311305
if suplab is not None:
312306
suplab.set_text(t)
313307
suplab.set_position((x, y))
314-
suplab.update_from(sup)
315-
sup.remove()
308+
suplab.set(**kwargs)
316309
else:
317-
suplab = sup
310+
suplab = self.text(x, y, t, **kwargs)
311+
setattr(self, info['name'], suplab)
318312
suplab._autopos = autopos
319-
setattr(self, info['name'], suplab)
320313
self.stale = True
321314
return suplab
322315

‎lib/matplotlib/text.py

Copy file name to clipboardExpand all lines: lib/matplotlib/text.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ def _get_text_metrics_with_cache_impl(
8080
@_docstring.interpd
8181
@_api.define_aliases({
8282
"color": ["c"],
83-
"fontfamily": ["family"],
8483
"fontproperties": ["font", "font_properties"],
85-
"horizontalalignment": ["ha"],
86-
"multialignment": ["ma"],
84+
"fontfamily": ["family"],
8785
"fontname": ["name"],
8886
"fontsize": ["size"],
8987
"fontstretch": ["stretch"],
9088
"fontstyle": ["style"],
9189
"fontvariant": ["variant"],
92-
"verticalalignment": ["va"],
9390
"fontweight": ["weight"],
91+
"horizontalalignment": ["ha"],
92+
"verticalalignment": ["va"],
93+
"multialignment": ["ma"],
9494
})
9595
class Text(Artist):
9696
"""Handle storing and drawing of text in window or data coordinates."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.