Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8526106

Browse files
committed
Add Figure methods get_suptitle(), get_subxlabel(), get_supylabel()
1 parent b86ebba commit 8526106

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/matplotlib/figure.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ def suptitle(self, t, **kwargs):
388388
'size': 'figure.titlesize', 'weight': 'figure.titleweight'}
389389
return self._suplabels(t, info, **kwargs)
390390

391+
def get_suptitle(self):
392+
"""Return the suptitle as string or an empty string if not set."""
393+
text_obj = self._suptitle
394+
return "" if text_obj is None else text_obj.get_text()
395+
391396
@_docstring.Substitution(x0=0.5, y0=0.01, name='supxlabel', ha='center',
392397
va='bottom', rc='label')
393398
@_docstring.copy(_suplabels)
@@ -398,6 +403,11 @@ def supxlabel(self, t, **kwargs):
398403
'size': 'figure.labelsize', 'weight': 'figure.labelweight'}
399404
return self._suplabels(t, info, **kwargs)
400405

406+
def get_supxlabel(self):
407+
"""Return the supxlabel as string or an empty string if not set."""
408+
text_obj = self._supxlabel
409+
return "" if text_obj is None else text_obj.get_text()
410+
401411
@_docstring.Substitution(x0=0.02, y0=0.5, name='supylabel', ha='left',
402412
va='center', rc='label')
403413
@_docstring.copy(_suplabels)
@@ -409,6 +419,11 @@ def supylabel(self, t, **kwargs):
409419
'weight': 'figure.labelweight'}
410420
return self._suplabels(t, info, **kwargs)
411421

422+
def get_supylabel(self):
423+
"""Return the supylabel as string or an empty string if not set."""
424+
text_obj = self._supylabel
425+
return "" if text_obj is None else text_obj.get_text()
426+
412427
def get_edgecolor(self):
413428
"""Get the edge color of the Figure rectangle."""
414429
return self.patch.get_edgecolor()

lib/matplotlib/tests/test_figure.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,19 @@ def test_suptitle_subfigures():
302302
assert sf2.get_facecolor() == (1.0, 1.0, 1.0, 1.0)
303303

304304

305+
def test_get_suptitle_supxlabel_supylabel():
306+
fig, ax = plt.subplots()
307+
assert fig.get_suptitle() == ""
308+
assert fig.get_supxlabel() == ""
309+
assert fig.get_supylabel() == ""
310+
fig.suptitle('suptitle')
311+
assert fig.get_suptitle() == 'suptitle'
312+
fig.supxlabel('supxlabel')
313+
assert fig.get_supxlabel() == 'supxlabel'
314+
fig.supylabel('supylabel')
315+
assert fig.get_supylabel() == 'supylabel'
316+
317+
305318
@image_comparison(['alpha_background'],
306319
# only test png and svg. The PDF output appears correct,
307320
# but Ghostscript does not preserve the background color.

0 commit comments

Comments
 (0)