|
3 | 3 | # Parts rewritten by Reinier Heeres <reinier@heeres.eu>
|
4 | 4 |
|
5 | 5 | import numpy as np
|
6 |
| - |
| 6 | +import matplotlib.transforms as mtransforms |
7 | 7 | from matplotlib import (
|
8 | 8 | artist, lines as mlines, axis as maxis, patches as mpatches, rcParams)
|
9 | 9 | from . import art3d, proj3d
|
@@ -398,12 +398,30 @@ def draw(self, renderer):
|
398 | 398 | renderer.close_group('axis3d')
|
399 | 399 | self.stale = False
|
400 | 400 |
|
401 |
| - # TODO: Get this to work properly when mplot3d supports |
402 |
| - # the transforms framework. |
403 |
| - def get_tightbbox(self, renderer): |
404 |
| - # Currently returns None so that Axis.get_tightbbox |
405 |
| - # doesn't return junk info. |
406 |
| - return None |
| 401 | + # TODO: Get this to work (more) properly when mplot3d supports the |
| 402 | + # transforms framework. |
| 403 | + def get_tightbbox(self, renderer, *, for_layout_only=False): |
| 404 | + # inherited docstring |
| 405 | + if not self.get_visible(): |
| 406 | + return |
| 407 | + # We have to directly access the internal data structures |
| 408 | + # (and hope they are up to date) because at draw time we |
| 409 | + # shift the ticks and their labels around in (x, y) space |
| 410 | + # based on the projection, the current view port, and their |
| 411 | + # position in 3D space. If we extend the transforms framework |
| 412 | + # into 3D we would not need to do this different book keeping |
| 413 | + # than we do in the normal axis |
| 414 | + ticks = [*self.majorTicks, *self.minorTicks] |
| 415 | + bb_1, bb_2 = self._get_tick_bboxes(ticks, renderer) |
| 416 | + other = [] |
| 417 | + |
| 418 | + if self.line.get_visible(): |
| 419 | + other.append(self.line.get_window_extent(renderer)) |
| 420 | + if (self.label.get_visible() and not for_layout_only and |
| 421 | + self.label.get_text()): |
| 422 | + other.append(self.label.get_window_extent(renderer)) |
| 423 | + |
| 424 | + return mtransforms.Bbox.union([*bb_1, *bb_2, *other]) |
407 | 425 |
|
408 | 426 | @property
|
409 | 427 | def d_interval(self):
|
|
0 commit comments