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

Sign up
Appearance settings

Commit d2d9d7d

Browse files
authored
Merge pull request matplotlib#7019 from dmkent/fix-suptitle-fontproperties
Check for fontproperties in figure.suptitle.
2 parents 5f352cb + 29f4679 commit d2d9d7d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

‎lib/matplotlib/figure.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ def suptitle(self, t, **kwargs):
523523
*verticalalignment* : 'top'
524524
The vertical alignment of the text
525525
526+
If the `fontproperties` keyword argument is given then the
527+
rcParams defaults for `fontsize` (`figure.titlesize`) and
528+
`fontweight` (`figure.titleweight`) will be ignored in favour
529+
of the `FontProperties` defaults.
530+
526531
A :class:`matplotlib.text.Text` instance is returned.
527532
528533
Example::
@@ -537,10 +542,11 @@ def suptitle(self, t, **kwargs):
537542
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
538543
kwargs['verticalalignment'] = 'top'
539544

540-
if 'fontsize' not in kwargs and 'size' not in kwargs:
541-
kwargs['size'] = rcParams['figure.titlesize']
542-
if 'fontweight' not in kwargs and 'weight' not in kwargs:
543-
kwargs['weight'] = rcParams['figure.titleweight']
545+
if 'fontproperties' not in kwargs:
546+
if 'fontsize' not in kwargs and 'size' not in kwargs:
547+
kwargs['size'] = rcParams['figure.titlesize']
548+
if 'fontweight' not in kwargs and 'weight' not in kwargs:
549+
kwargs['weight'] = rcParams['figure.titleweight']
544550

545551
sup = self.text(x, y, t, **kwargs)
546552
if self._suptitle is not None:

‎lib/matplotlib/tests/test_figure.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ def test_suptitle():
100100
fig.suptitle('title', color='g', rotation='30')
101101

102102

103+
@cleanup
104+
def test_suptitle_fontproperties():
105+
from matplotlib.font_manager import FontProperties
106+
fig = plt.figure()
107+
ax = fig.add_subplot(1, 1, 1)
108+
fps = FontProperties(size='large', weight='bold')
109+
txt = fig.suptitle('fontprops title', fontproperties=fps)
110+
assert_equal(txt.get_fontsize(), fps.get_size_in_points())
111+
assert_equal(txt.get_weight(), fps.get_weight())
112+
113+
103114
@image_comparison(baseline_images=['alpha_background'],
104115
# only test png and svg. The PDF output appears correct,
105116
# but Ghostscript does not preserve the background color.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /