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

Skip to content

Commit 9d1c876

Browse files
itziakostacaswell
authored andcommitted
Add draft implementation of the get_window_extent method
1 parent cad373f commit 9d1c876

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/matplotlib/text.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,5 +2086,39 @@ def draw(self, renderer):
20862086

20872087
Text.draw(self, renderer)
20882088

2089+
def get_window_extent(self, renderer=None):
2090+
'''
2091+
Return a :class:`~matplotlib.transforms.Bbox` object bounding
2092+
the text and arrow annotation, in display units.
2093+
2094+
*renderer* defaults to the _renderer attribute of the text
2095+
object. This is not assigned until the first execution of
2096+
:meth:`draw`, so you must use this kwarg if you want
2097+
to call :meth:`get_window_extent` prior to the first
2098+
:meth:`draw`. For getting web page regions, it is
2099+
simpler to call the method after saving the figure. The
2100+
*dpi* used defaults to self.figure.dpi; the renderer dpi is
2101+
irrelevant.
2102+
2103+
'''
2104+
arrow = self.arrow
2105+
arrow_patch = self.arrow_patch
2106+
2107+
text_bbox = Text.get_window_extent(self, renderer=renderer)
2108+
if text_bbox.width == 0.0 and text_bbox.height == 0.0:
2109+
bboxes = []
2110+
else:
2111+
bboxes = [text_bbox]
2112+
2113+
if self.arrow is not None:
2114+
bboxes.append(arrow.get_window_extent(renderer=renderer))
2115+
elif self.arrow_patch is not None:
2116+
bboxes.append(arrow_patch.get_window_extent(renderer=renderer))
2117+
2118+
if len(bboxes) == 0:
2119+
return Bbox.from_bounds(self._x, self._y, 0.0, 0.0)
2120+
else:
2121+
return Bbox.union(bboxes)
2122+
20892123

20902124
docstring.interpd.update(Annotation=Annotation.__init__.__doc__)

0 commit comments

Comments
 (0)