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

Method get_window_extent

lib/matplotlib/text.py:1033–1080  ·  view source on GitHub ↗

Return the `.Bbox` bounding the text, in display units. In addition to being used internally, this is useful for specifying clickable regions in a png file on a web page. Parameters ---------- renderer : Renderer, optional A renderer is

(self, renderer=None, dpi=None)

Source from the content-addressed store, hash-verified

1031 return self._verticalalignment
1032
1033 def get_window_extent(self, renderer=None, dpi=None):
1034 """
1035 Return the `.Bbox` bounding the text, in display units.
1036
1037 In addition to being used internally, this is useful for specifying
1038 clickable regions in a png file on a web page.
1039
1040 Parameters
1041 ----------
1042 renderer : Renderer, optional
1043 A renderer is needed to compute the bounding box. If the artist
1044 has already been drawn, the renderer is cached; thus, it is only
1045 necessary to pass this argument when calling `get_window_extent`
1046 before the first draw. In practice, it is usually easier to
1047 trigger a draw first, e.g. by calling
1048 `~.Figure.draw_without_rendering` or ``plt.show()``.
1049
1050 dpi : float, optional
1051 The dpi value for computing the bbox, defaults to
1052 ``self.get_figure(root=True).dpi`` (*not* the renderer dpi); should be set
1053 e.g. if to match regions with a figure saved with a custom dpi value.
1054 """
1055 if not self.get_visible():
1056 return Bbox.unit()
1057
1058 fig = self.get_figure(root=True)
1059 if dpi is None:
1060 dpi = fig.dpi
1061 if self.get_text() == '':
1062 with cbook._setattr_cm(fig, dpi=dpi):
1063 tx, ty = self._get_xy_display()
1064 return Bbox.from_bounds(tx, ty, 0, 0)
1065
1066 if renderer is not None:
1067 self._renderer = renderer
1068 if self._renderer is None:
1069 self._renderer = fig._get_renderer()
1070 if self._renderer is None:
1071 raise RuntimeError(
1072 "Cannot get window extent of text w/o renderer. You likely "
1073 "want to call 'figure.draw_without_rendering()' first.")
1074
1075 with cbook._setattr_cm(fig, dpi=dpi):
1076 bbox, _, _ = self._get_layout(self._renderer)
1077 x, y = self.get_unitless_position()
1078 x, y = self.get_transform().transform((x, y))
1079 bbox = bbox.translated(x, y)
1080 return bbox
1081
1082 def get_tightbbox(self, renderer=None):
1083 if not self.get_visible() or self.get_text() == "":

Callers 15

_char_index_atMethod · 0.95
containsMethod · 0.45
_get_wrap_line_widthMethod · 0.45
__call__Method · 0.45
_get_xy_transformMethod · 0.45
update_positionsMethod · 0.45
get_window_extentMethod · 0.45
_get_ticklabel_bboxesMethod · 0.45
get_tightbboxMethod · 0.45

Calls 12

get_textMethod · 0.95
_get_xy_displayMethod · 0.95
_get_layoutMethod · 0.95
get_unitless_positionMethod · 0.95
unitMethod · 0.80
from_boundsMethod · 0.80
translatedMethod · 0.80
get_visibleMethod · 0.45
get_figureMethod · 0.45
_get_rendererMethod · 0.45
transformMethod · 0.45
get_transformMethod · 0.45

Tested by 2

test_rotation_modeFunction · 0.36