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

Commit6d8c9c1

Browse files
committed
FIX: CL avoid fully collapsed axes
1 parentdfb8936 commit6d8c9c1

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

‎lib/matplotlib/_constrained_layout.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ def _in_same_row(rownum0min, rownum0max, rownumCmin, rownumCmax):
6666
orrownumCmin<=rownum0max<=rownumCmax)
6767

6868

69+
def_axes_all_finite_sized(fig):
70+
"""
71+
helper function to make sure all axes in the
72+
figure have a finite width and height. If not, return False
73+
"""
74+
foraxinfig.axes:
75+
ifax._layoutboxisnotNone:
76+
newpos=ax._poslayoutbox.get_rect()
77+
ifnewpos[2]<=0ornewpos[3]<=0:
78+
returnFalse
79+
returnTrue
80+
81+
6982
######################################################
7083
defdo_constrained_layout(fig,renderer,h_pad,w_pad,
7184
hspace=None,wspace=None):
@@ -132,6 +145,14 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
132145
133146
'''
134147

148+
try:
149+
iffig.canvas.toolbar._activein ('PAN','ZOOM'):
150+
# don't do constrained layout during zoom and pan.
151+
return
152+
exceptAttributeError:
153+
# not toolbar, or no _active attribute..
154+
pass
155+
135156
invTransFig=fig.transFigure.inverted().transform_bbox
136157

137158
# list of unique gridspecs that contain child axes:
@@ -187,8 +208,6 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
187208
figlb=fig._layoutbox
188209
forchildinfiglb.children:
189210
ifchild._is_gridspec_layoutbox():
190-
# farm the gridspec layout out.
191-
#
192211
# This routine makes all the subplot spec containers
193212
# have the correct arrangement. It just stacks the
194213
# subplot layoutboxes in the correct order...
@@ -199,15 +218,21 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
199218

200219
fig._layoutbox.constrained_layout_called+=1
201220
fig._layoutbox.update_variables()
202-
# Now set the position of the axes...
203-
foraxinfig.axes:
204-
ifax._layoutboxisnotNone:
205-
newpos=ax._poslayoutbox.get_rect()
206-
# Now set the new position.
207-
# ax.set_position will zero out the layout for
208-
# this axis, allowing users to hard-code the position,
209-
# so this does the same w/o zeroing layout.
210-
ax._set_position(newpos,which='original')
221+
222+
# check if any axes collapsed to zero. If not, don't change positions:
223+
if_axes_all_finite_sized(fig):
224+
# Now set the position of the axes...
225+
foraxinfig.axes:
226+
ifax._layoutboxisnotNone:
227+
newpos=ax._poslayoutbox.get_rect()
228+
# Now set the new position.
229+
# ax.set_position will zero out the layout for
230+
# this axis, allowing users to hard-code the position,
231+
# so this does the same w/o zeroing layout.
232+
ax._set_position(newpos,which='original')
233+
else:
234+
warnings.warn('constrained_layout not applied. At least '
235+
'one axes collapsed to zero width or height.')
211236

212237

213238
def_make_ghost_gridspec_slots(fig,gs):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp