Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf18bd14

Browse files
committed
ENH: implement get_tightbbox on Axis3D
1 parent5451b25 commitf18bd14

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

‎lib/mpl_toolkits/mplot3d/axes3d.py‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
279279
ratio
280280
'auto' automatic; fill the position rectangle with data.
281281
This will let the ratio between the size of the
282-
(pseudo-) bounding box be free and will not adjust
283-
anything at draw time.
282+
(pseudo-) bounding box be free and will not
283+
adjustanything at draw time.
284284
======== =================================================
285285
286286
adjustable : None or {'box', 'datalim'}, optional
@@ -2861,6 +2861,27 @@ def permutation_matrices(n):
28612861

28622862
returnpolygons
28632863

2864+
defget_tightbbox(self,renderer,call_axes_locator=True,
2865+
bbox_extra_artists=None,*,for_layout_only=False):
2866+
ret=super().get_tightbbox(renderer,
2867+
call_axes_locator=call_axes_locator,
2868+
bbox_extra_artists=bbox_extra_artists,
2869+
for_layout_only=for_layout_only)
2870+
batch= [ret]
2871+
ifself._axis3don:
2872+
foraxisinself._get_axis_list():
2873+
ifaxis.get_visible():
2874+
try:
2875+
axis_bb=axis.get_tightbbox(
2876+
renderer,
2877+
for_layout_only=for_layout_only
2878+
)
2879+
exceptTypeError:
2880+
# in case downstream library has redefined axis:
2881+
axis_bb=axis.get_tightbbox(renderer)
2882+
ifaxis_bb:
2883+
batch.append(axis_bb)
2884+
returnmtransforms.Bbox.union(batch)
28642885

28652886
docstring.interpd.update(Axes3D=artist.kwdoc(Axes3D))
28662887
docstring.dedent_interpd(Axes3D.__init__)

‎lib/mpl_toolkits/mplot3d/axis3d.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Parts rewritten by Reinier Heeres <reinier@heeres.eu>
44

55
importnumpyasnp
6-
6+
importmatplotlib.transformsasmtransforms
77
frommatplotlibimport (
88
artist,linesasmlines,axisasmaxis,patchesasmpatches,rcParams)
99
from .importart3d,proj3d
@@ -398,12 +398,30 @@ def draw(self, renderer):
398398
renderer.close_group('axis3d')
399399
self.stale=False
400400

401-
# TODO: Get this to work properly when mplot3d supports
402-
# the transforms framework.
403-
defget_tightbbox(self,renderer):
404-
# Currently returns None so that Axis.get_tightbbox
405-
# doesn't return junk info.
406-
returnNone
401+
# TODO: Get this to work (more) properly when mplot3d supports the
402+
# transforms framework.
403+
defget_tightbbox(self,renderer,*,for_layout_only=False):
404+
# inherited docstring
405+
ifnotself.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+
ifself.line.get_visible():
419+
other.append(self.line.get_window_extent(renderer))
420+
if (self.label.get_visible()andnotfor_layout_onlyand
421+
self.label.get_text()):
422+
other.append(self.label.get_window_extent(renderer))
423+
424+
returnmtransforms.Bbox.union([*bb_1,*bb_2,*other])
407425

408426
@property
409427
defd_interval(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp