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

Commit65bedc5

Browse files
committed
FIX: errors in get_position changes
1 parent9c9a660 commit65bedc5

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,9 @@ def get_position(self, original=False):
839839
iforiginal:
840840
returnself._originalPosition.frozen()
841841
else:
842-
self.apply_aspect()
842+
locator=self.get_axes_locator()
843+
ifnotlocator:
844+
self.apply_aspect()
843845
returnself._position.frozen()
844846

845847
defset_position(self,pos,which='both'):
@@ -861,7 +863,7 @@ def set_position(self, pos, which='both'):
861863
Determines which position variables to change.
862864
863865
"""
864-
self._set_position(pos,which='both')
866+
self._set_position(pos,which=which)
865867
# because this is being called externally to the library we
866868
# zero the constrained layout parts.
867869
self._layoutbox=None

‎lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,9 +2271,9 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22712271
ifbboxisnotNoneand (bbox.width!=0orbbox.height!=0):
22722272
bb.append(bbox)
22732273

2274-
foraxinself.axes:
2275-
ifax.get_visible():
2276-
bb.append(ax.get_tightbbox(renderer,bbox_extra_artists))
2274+
bb.extend(
2275+
ax.get_tightbbox(renderer,bbox_extra_artists=bbox_extra_artists)
2276+
foraxinself.axesifax.get_visible())
22772277

22782278
iflen(bb)==0:
22792279
returnself.bbox_inches

‎lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,6 +5781,19 @@ def test_zoom_inset():
57815781
xx,rtol=1e-4)
57825782

57835783

5784+
deftest_set_position():
5785+
fig,ax=plt.subplots()
5786+
ax.set_aspect(3.)
5787+
ax.set_position([0.1,0.1,0.4,0.4],which='both')
5788+
assertnp.allclose(ax.get_position().width,0.1)
5789+
ax.set_aspect(2.)
5790+
ax.set_position([0.1,0.1,0.4,0.4],which='original')
5791+
assertnp.allclose(ax.get_position().width,0.15)
5792+
ax.set_aspect(3.)
5793+
ax.set_position([0.1,0.1,0.4,0.4],which='active')
5794+
assertnp.allclose(ax.get_position().width,0.1)
5795+
5796+
57845797
deftest_spines_properbbox_after_zoom():
57855798
fig,ax=plt.subplots()
57865799
bb=ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())

‎lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ def __init__(self, ax, direction):
321321
raiseKeyError("direction must be one of left, right, bottom, top")
322322

323323
def__call__(self,renderer):
324-
vl= [self._get_func(ax.get_tightbbox(renderer,False),
325-
ax.bbox)foraxinself._ax_list]
324+
vl= [self._get_func(ax.get_tightbbox(renderer,
325+
call_axes_locator=False),
326+
ax.bbox)
327+
foraxinself._ax_list]
326328
returnmax(vl)

‎lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ def _remove_method(h):
329329
returnax2
330330

331331
defget_tightbbox(self,renderer,call_axes_locator=True):
332-
bbs= [ax.get_tightbbox(renderer,call_axes_locator)
332+
bbs= [ax.get_tightbbox(renderer,call_axes_locator=call_axes_locator)
333333
foraxinself.parasites]
334-
bbs.append(super().get_tightbbox(renderer,call_axes_locator))
334+
bbs.append(super().get_tightbbox(renderer,
335+
call_axes_locator=call_axes_locator))
335336
returnBbox.union([bforbinbbsifb.width!=0orb.height!=0])
336337

337338

‎lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
frommpl_toolkits.axes_grid1importhost_subplot
66
frommpl_toolkits.axes_grid1importmake_axes_locatable
77
frommpl_toolkits.axes_grid1importAxesGrid
8+
frommpl_toolkits.axes_grid1importImageGrid
89
frommpl_toolkits.axes_grid1.inset_locatorimport (
910
zoomed_inset_axes,
1011
mark_inset,
@@ -381,3 +382,28 @@ def test_anchored_direction_arrows_many_args():
381382
sep_x=-0.06,sep_y=-0.08,back_length=0.1,head_width=9,
382383
head_length=10,tail_width=5)
383384
ax.add_artist(direction_arrows)
385+
386+
387+
deftest_axes_locatable_position():
388+
fig,ax=plt.subplots()
389+
divider=make_axes_locatable(ax)
390+
cax=divider.append_axes('right',size='5%',pad='2%')
391+
fig.canvas.draw()
392+
assertnp.isclose(cax.get_position(original=False).width,
393+
0.03621495327102808)
394+
395+
396+
@image_comparison(baseline_images=['image_grid'],extensions=['png'],
397+
remove_text=True,style='mpl20',
398+
savefig_kwarg={'bbox_inches':'tight'})
399+
deftest_image_grid():
400+
# test that image grid works with bbox_inches=tight.
401+
im=np.arange(100)
402+
im.shape=10,10
403+
404+
fig=plt.figure(1, (4.,4.))
405+
grid=ImageGrid(fig,111,nrows_ncols=(2,2),axes_pad=0.1)
406+
407+
foriinrange(4):
408+
grid[i].imshow(im)
409+
grid[i].set_title('test {0}{0}'.format(i))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp