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

Simplify Figure._suplabels. #27728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions 27 lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ def _suplabels(self, t, info, **kwargs):
Additional kwargs are `matplotlib.text.Text` properties.
"""

suplab = getattr(self, info['name'])

x = kwargs.pop('x', None)
y = kwargs.pop('y', None)
if info['name'] in ['_supxlabel', '_suptitle']:
Expand All @@ -300,29 +298,24 @@ def _suplabels(self, t, info, **kwargs):
if y is None:
y = info['y0']

if 'horizontalalignment' not in kwargs and 'ha' not in kwargs:
kwargs['horizontalalignment'] = info['ha']
if 'verticalalignment' not in kwargs and 'va' not in kwargs:
kwargs['verticalalignment'] = info['va']
if 'rotation' not in kwargs:
kwargs['rotation'] = info['rotation']
kwargs = cbook.normalize_kwargs(kwargs, Text)
kwargs.setdefault('horizontalalignment', info['ha'])
kwargs.setdefault('verticalalignment', info['va'])
kwargs.setdefault('rotation', info['rotation'])

if 'fontproperties' not in kwargs:
if 'fontsize' not in kwargs and 'size' not in kwargs:
kwargs['size'] = mpl.rcParams[info['size']]
if 'fontweight' not in kwargs and 'weight' not in kwargs:
kwargs['weight'] = mpl.rcParams[info['weight']]
kwargs.setdefault('fontsize', mpl.rcParams[info['size']])
kwargs.setdefault('fontweight', mpl.rcParams[info['weight']])

sup = self.text(x, y, t, **kwargs)
suplab = getattr(self, info['name'])
if suplab is not None:
suplab.set_text(t)
suplab.set_position((x, y))
suplab.update_from(sup)
sup.remove()
suplab.set(**kwargs)
else:
suplab = sup
suplab = self.text(x, y, t, **kwargs)
setattr(self, info['name'], suplab)
suplab._autopos = autopos
setattr(self, info['name'], suplab)
self.stale = True
return suplab

Expand Down
8 changes: 4 additions & 4 deletions 8 lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ def _get_text_metrics_with_cache_impl(
@_docstring.interpd
@_api.define_aliases({
"color": ["c"],
"fontfamily": ["family"],
"fontproperties": ["font", "font_properties"],
"horizontalalignment": ["ha"],
"multialignment": ["ma"],
"fontfamily": ["family"],
"fontname": ["name"],
"fontsize": ["size"],
"fontstretch": ["stretch"],
"fontstyle": ["style"],
"fontvariant": ["variant"],
"verticalalignment": ["va"],
"fontweight": ["weight"],
"horizontalalignment": ["ha"],
"verticalalignment": ["va"],
"multialignment": ["ma"],
})
class Text(Artist):
"""Handle storing and drawing of text in window or data coordinates."""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.