X Tutup
Skip to content
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
14 changes: 10 additions & 4 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ def suptitle(self, t, **kwargs):
*verticalalignment* : 'top'
The vertical alignment of the text

If the `fontproperties` keyword argument is given then the
rcParams defaults for `fontsize` (`figure.titlesize`) and
`fontweight` (`figure.titleweight`) will be ignored in favour
of the `FontProperties` defaults.

A :class:`matplotlib.text.Text` instance is returned.

Example::
Expand All @@ -537,10 +542,11 @@ def suptitle(self, t, **kwargs):
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
kwargs['verticalalignment'] = 'top'

if 'fontsize' not in kwargs and 'size' not in kwargs:
kwargs['size'] = rcParams['figure.titlesize']
if 'fontweight' not in kwargs and 'weight' not in kwargs:
kwargs['weight'] = rcParams['figure.titleweight']
if 'fontproperties' not in kwargs:
if 'fontsize' not in kwargs and 'size' not in kwargs:
kwargs['size'] = rcParams['figure.titlesize']
if 'fontweight' not in kwargs and 'weight' not in kwargs:
kwargs['weight'] = rcParams['figure.titleweight']

sup = self.text(x, y, t, **kwargs)
if self._suptitle is not None:
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ def test_suptitle():
fig.suptitle('title', color='g', rotation='30')


@cleanup
def test_suptitle_fontproperties():
from matplotlib.font_manager import FontProperties
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this it's own test with the @cleanup decorator? Just checking that font size and weight are correct is probably enough for this test.

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
fps = FontProperties(size='large', weight='bold')
txt = fig.suptitle('fontprops title', fontproperties=fps)
assert_equal(txt.get_fontsize(), fps.get_size_in_points())
assert_equal(txt.get_weight(), fps.get_weight())


@image_comparison(baseline_images=['alpha_background'],
# only test png and svg. The PDF output appears correct,
# but Ghostscript does not preserve the background color.
Expand Down
X Tutup