8000 Merge pull request #7019 from dmkent/fix-suptitle-fontproperties · matplotlib/matplotlib@cf8e669 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf8e669

Browse files
NelleVtacaswell
authored andcommitted
Merge pull request #7019 from dmkent/fix-suptitle-fontproperties
Check for fontproperties in figure.suptitle.
1 parent 622f53a commit cf8e669

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
@@ -522,6 +522,11 @@ def suptitle(self, t, **kwargs):
522522
*verticalalignment* : 'top'
523523
The vertical alignment of the text
524524
525+
If the `fontproperties` keyword argument is given then the
526+
rcParams defaults for `fontsize` (`figure.titlesize`) and
527+
`fontweight` (`figure.titleweight`) will be ignored in favour
528+
of the `FontProperties` defaults.
529+
525530
A :class:`matplotlib.text.Text` instance is returned.
526531
527532
Example::
@@ -536,10 +541,11 @@ def suptitle(self, t, **kwargs):
10000
536541
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
537542
kwargs['verticalalignment'] = 'top'
538543

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

544550
sup = self.text(x, y, t, **kwargs)
545551
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
@@ -99,6 +99,17 @@ def test_suptitle():
9999
fig.suptitle('title', color='g', rotation='30')
100100

101101

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

0 commit comments

Comments
 (0)
0