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

Method get_window_extent

lib/matplotlib/spines.py:142–198  ·  view source on GitHub ↗

Return the window extent of the spines in display space, including padding for ticks (but not their labels) See Also -------- matplotlib.axes.Axes.get_tightbbox matplotlib.axes.Axes.get_window_extent

(self, renderer=None)

Source from the content-addressed store, hash-verified

140 return super().get_patch_transform()
141
142 def get_window_extent(self, renderer=None):
143 """
144 Return the window extent of the spines in display space, including
145 padding for ticks (but not their labels)
146
147 See Also
148 --------
149 matplotlib.axes.Axes.get_tightbbox
150 matplotlib.axes.Axes.get_window_extent
151 """
152 # make sure the location is updated so that transforms etc are correct:
153 self._adjust_location()
154 bb = super().get_window_extent(renderer=renderer)
155 if self.axis is None or not self.axis.get_visible():
156 return bb
157 bboxes = [bb]
158 drawn_ticks = self.axis._update_ticks()
159
160 major_tick = next(iter({*drawn_ticks} & {*self.axis.majorTicks}), None)
161 minor_tick = next(iter({*drawn_ticks} & {*self.axis.minorTicks}), None)
162 for tick in [major_tick, minor_tick]:
163 if tick is None:
164 continue
165 bb0 = bb.frozen()
166 tickl = tick._size
167 tickdir = tick._tickdir
168 if tickdir == 'out':
169 padout = 1
170 padin = 0
171 elif tickdir == 'in':
172 padout = 0
173 padin = 1
174 else:
175 padout = 0.5
176 padin = 0.5
177 dpi = self.get_figure(root=True).dpi
178 padout = padout * tickl / 72 * dpi
179 padin = padin * tickl / 72 * dpi
180
181 if tick.tick1line.get_visible():
182 if self.spine_type == 'left':
183 bb0.x0 = bb0.x0 - padout
184 bb0.x1 = bb0.x1 + padin
185 elif self.spine_type == 'bottom':
186 bb0.y0 = bb0.y0 - padout
187 bb0.y1 = bb0.y1 + padin
188
189 if tick.tick2line.get_visible():
190 if self.spine_type == 'right':
191 bb0.x1 = bb0.x1 + padout
192 bb0.x0 = bb0.x0 - padin
193 elif self.spine_type == 'top':
194 bb0.y1 = bb0.y1 + padout
195 bb0.y0 = bb0.y0 - padout
196 bboxes.append(bb0)
197
198 return mtransforms.Bbox.union(bboxes)
199

Callers

nothing calls this directly

Calls 6

_adjust_locationMethod · 0.95
unionMethod · 0.80
get_visibleMethod · 0.45
_update_ticksMethod · 0.45
frozenMethod · 0.45
get_figureMethod · 0.45

Tested by

no test coverage detected