MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / get_tightbbox

Method get_tightbbox

lib/matplotlib/figure.py:1808–1879  ·  view source on GitHub ↗

Return a (tight) bounding box of the figure *in inches*. Note that `.FigureBase` differs from all other artists, which return their `.Bbox` in pixels. Artists that have ``artist.set_in_layout(False)`` are not included in the bbox. Parameters

(self, renderer=None, *, bbox_extra_artists=None)

Source from the content-addressed store, hash-verified

1806 return bbox_artists
1807
1808 def get_tightbbox(self, renderer=None, *, bbox_extra_artists=None):
1809 """
1810 Return a (tight) bounding box of the figure *in inches*.
1811
1812 Note that `.FigureBase` differs from all other artists, which return
1813 their `.Bbox` in pixels.
1814
1815 Artists that have ``artist.set_in_layout(False)`` are not included
1816 in the bbox.
1817
1818 Parameters
1819 ----------
1820 renderer : `.RendererBase` subclass
1821 Renderer that will be used to draw the figures (i.e.
1822 ``fig.canvas.get_renderer()``)
1823
1824 bbox_extra_artists : list of `.Artist` or ``None``
1825 List of artists to include in the tight bounding box. If
1826 ``None`` (default), then all artist children of each Axes are
1827 included in the tight bounding box.
1828
1829 Returns
1830 -------
1831 `.BboxBase`
1832 containing the bounding box (in figure inches).
1833 """
1834
1835 if renderer is None:
1836 renderer = self.get_figure(root=True)._get_renderer()
1837
1838 bb = []
1839 if bbox_extra_artists is None:
1840 artists = [artist for artist in self.get_children()
1841 if (artist not in self.axes and artist.get_visible()
1842 and artist.get_in_layout())]
1843 else:
1844 artists = bbox_extra_artists
1845
1846 for a in artists:
1847 bbox = a.get_tightbbox(renderer)
1848 if bbox is not None:
1849 bb.append(bbox)
1850
1851 for ax in self.axes:
1852 if ax.get_visible():
1853 # some Axes don't take the bbox_extra_artists kwarg so we
1854 # need this conditional....
1855 try:
1856 bbox = ax.get_tightbbox(
1857 renderer, bbox_extra_artists=bbox_extra_artists)
1858 except TypeError:
1859 bbox = ax.get_tightbbox(renderer)
1860 bb.append(bbox)
1861 bb = [b for b in bb
1862 if (np.isfinite(b.width) and np.isfinite(b.height)
1863 and (b.width != 0 or b.height != 0))]
1864
1865 isfigure = hasattr(self, 'bbox_inches')

Callers

nothing calls this directly

Calls 8

get_figureMethod · 0.95
get_childrenMethod · 0.95
TransformedBboxClass · 0.90
get_in_layoutMethod · 0.80
unionMethod · 0.80
_get_rendererMethod · 0.45
get_visibleMethod · 0.45
invertedMethod · 0.45

Tested by

no test coverage detected