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

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
4 changes: 4 additions & 0 deletions doc/users/next_whats_new/get_suptitle.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``Figure.get_suptitle()``, ``Figure.get_supxlabel()``, ``Figure.get_supylabel()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These methods return the strings set by ``Figure.suptitle()``, ``Figure.supxlabel()``
and ``Figure.supylabel()`` respectively.
15 changes: 15 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ def suptitle(self, t, **kwargs):
'size': 'figure.titlesize', 'weight': 'figure.titleweight'}
return self._suplabels(t, info, **kwargs)

def get_suptitle(self):
"""Return the suptitle as string or an empty string if not set."""
text_obj = self._suptitle
return "" if text_obj is None else text_obj.get_text()
Comment thread
oscargus marked this conversation as resolved.

@_docstring.Substitution(x0=0.5, y0=0.01, name='supxlabel', ha='center',
va='bottom', rc='label')
@_docstring.copy(_suplabels)
Expand All @@ -398,6 +403,11 @@ def supxlabel(self, t, **kwargs):
'size': 'figure.labelsize', 'weight': 'figure.labelweight'}
return self._suplabels(t, info, **kwargs)

def get_supxlabel(self):
"""Return the supxlabel as string or an empty string if not set."""
text_obj = self._supxlabel
return "" if text_obj is None else text_obj.get_text()

@_docstring.Substitution(x0=0.02, y0=0.5, name='supylabel', ha='left',
va='center', rc='label')
@_docstring.copy(_suplabels)
Expand All @@ -409,6 +419,11 @@ def supylabel(self, t, **kwargs):
'weight': 'figure.labelweight'}
return self._suplabels(t, info, **kwargs)

def get_supylabel(self):
"""Return the supylabel as string or an empty string if not set."""
text_obj = self._supylabel
return "" if text_obj is None else text_obj.get_text()

def get_edgecolor(self):
"""Get the edge color of the Figure rectangle."""
return self.patch.get_edgecolor()
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/figure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ class FigureBase(Artist):
def get_children(self) -> list[Artist]: ...
def contains(self, mouseevent: MouseEvent) -> tuple[bool, dict[Any, Any]]: ...
def suptitle(self, t: str, **kwargs) -> Text: ...
def get_suptitle(self) -> str: ...
def supxlabel(self, t: str, **kwargs) -> Text: ...
def get_supxlabel(self) -> str: ...
def supylabel(self, t: str, **kwargs) -> Text: ...
def get_supylabel(self) -> str: ...
def get_edgecolor(self) -> ColorType: ...
def get_facecolor(self) -> ColorType: ...
def get_frameon(self) -> bool: ...
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ def test_suptitle_subfigures():
assert sf2.get_facecolor() == (1.0, 1.0, 1.0, 1.0)


def test_get_suptitle_supxlabel_supylabel():
fig, ax = plt.subplots()
assert fig.get_suptitle() == ""
assert fig.get_supxlabel() == ""
assert fig.get_supylabel() == ""
fig.suptitle('suptitle')
assert fig.get_suptitle() == 'suptitle'
fig.supxlabel('supxlabel')
assert fig.get_supxlabel() == 'supxlabel'
fig.supylabel('supylabel')
assert fig.get_supylabel() == 'supylabel'


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