Update the title position based on the bounding box enclosing all the ticklabels and x-axis spine and xlabel...
(self, renderer)
| 3212 | y_stickies, self.set_ybound) |
| 3213 | |
| 3214 | def _update_title_position(self, renderer): |
| 3215 | """ |
| 3216 | Update the title position based on the bounding box enclosing |
| 3217 | all the ticklabels and x-axis spine and xlabel... |
| 3218 | """ |
| 3219 | if self._autotitlepos is not None and not self._autotitlepos: |
| 3220 | _log.debug('title position was updated manually, not adjusting') |
| 3221 | return |
| 3222 | |
| 3223 | titles = (self.title, self._left_title, self._right_title) |
| 3224 | |
| 3225 | if not any(title.get_text() for title in titles): |
| 3226 | # If the titles are all empty, there is no need to update their positions. |
| 3227 | return |
| 3228 | |
| 3229 | # Need to check all our twins too, aligned axes, and all the children |
| 3230 | # as well. |
| 3231 | axs = set() |
| 3232 | axs.update(self.child_axes) |
| 3233 | axs.update(self._twinned_axes.get_siblings(self)) |
| 3234 | axs.update( |
| 3235 | self.get_figure(root=False)._align_label_groups['title'].get_siblings(self)) |
| 3236 | |
| 3237 | for ax in self.child_axes: # Child positions must be updated first. |
| 3238 | locator = ax.get_axes_locator() |
| 3239 | ax.apply_aspect(locator(self, renderer) if locator else None) |
| 3240 | |
| 3241 | top = -np.inf |
| 3242 | for ax in axs: |
| 3243 | bb = None |
| 3244 | if (ax.xaxis.get_ticks_position() in ['top', 'unknown'] or |
| 3245 | ax.xaxis.get_label_position() == 'top'): |
| 3246 | bb = ax.xaxis.get_tightbbox(renderer) |
| 3247 | if bb is None: |
| 3248 | # Extent of the outline for colorbars, of the axes otherwise. |
| 3249 | bb = ax.spines.get("outline", ax).get_window_extent() |
| 3250 | top = max(top, bb.ymax) |
| 3251 | |
| 3252 | for title in titles: |
| 3253 | x, _ = title.get_position() |
| 3254 | # need to start again in case of window resizing |
| 3255 | title.set_position((x, 1.0)) |
| 3256 | if title.get_text(): |
| 3257 | for ax in axs: |
| 3258 | ax.yaxis.get_tightbbox(renderer) # update offsetText |
| 3259 | if ax.yaxis.offsetText.get_text(): |
| 3260 | bb = ax.yaxis.offsetText.get_tightbbox(renderer) |
| 3261 | if bb.intersection(title.get_tightbbox(renderer), bb): |
| 3262 | top = bb.ymax |
| 3263 | if top < 0: |
| 3264 | # the top of Axes is not even on the figure, so don't try and |
| 3265 | # automatically place it. |
| 3266 | _log.debug('top of Axes not in the figure, so title not moved') |
| 3267 | return |
| 3268 | if title.get_window_extent(renderer).ymin < top: |
| 3269 | _, y = self.transAxes.inverted().transform((0, top)) |
| 3270 | title.set_position((x, y)) |
| 3271 | # empirically, this doesn't always get the min to top, |