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

FIX: errors in get_position changes#12363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletionslib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -835,7 +835,9 @@ def get_position(self, original=False):
if original:
return self._originalPosition.frozen()
else:
self.apply_aspect()
locator = self.get_axes_locator()
if not locator:
self.apply_aspect()
return self._position.frozen()

def set_position(self, pos, which='both'):
Expand All@@ -857,7 +859,7 @@ def set_position(self, pos, which='both'):
Determines which position variables to change.

"""
self._set_position(pos, which='both')
self._set_position(pos, which=which)
# because this is being called externally to the library we
# zero the constrained layout parts.
self._layoutbox = None
Expand Down
6 changes: 3 additions & 3 deletionslib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2296,9 +2296,9 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
bb.append(bbox)

for ax in self.axes:
ifax.get_visible():
bb.append(ax.get_tightbbox(renderer, bbox_extra_artists))
bb.extend(
ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
for ax in self.axes ifax.get_visible())

if len(bb) == 0:
return self.bbox_inches
Expand Down
13 changes: 13 additions & 0 deletionslib/matplotlib/tests/test_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5789,6 +5789,19 @@ def test_zoom_inset():
xx, rtol=1e-4)


def test_set_position():
fig, ax = plt.subplots()
ax.set_aspect(3.)
ax.set_position([0.1, 0.1, 0.4, 0.4], which='both')
assert np.allclose(ax.get_position().width, 0.1)
ax.set_aspect(2.)
ax.set_position([0.1, 0.1, 0.4, 0.4], which='original')
assert np.allclose(ax.get_position().width, 0.15)
ax.set_aspect(3.)
ax.set_position([0.1, 0.1, 0.4, 0.4], which='active')
assert np.allclose(ax.get_position().width, 0.1)


def test_spines_properbbox_after_zoom():
fig, ax = plt.subplots()
bb = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
Expand Down
3 changes: 2 additions & 1 deletionlib/mpl_toolkits/axes_grid1/axes_size.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -305,6 +305,7 @@ def __init__(self, ax, direction):

def __call__(self, renderer):
get_func = self._get_func_map[self._direction]
vl = [get_func(ax.get_tightbbox(renderer, False), ax.bbox)
vl = [get_func(ax.get_tightbbox(renderer, call_axes_locator=False),
ax.bbox)
for ax in self._ax_list]
return max(vl)
5 changes: 3 additions & 2 deletionslib/mpl_toolkits/axes_grid1/parasite_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -327,9 +327,10 @@ def _remove_method(h):
return ax2

def get_tightbbox(self, renderer, call_axes_locator=True):
bbs = [ax.get_tightbbox(renderer, call_axes_locator)
bbs = [ax.get_tightbbox(renderer, call_axes_locator=call_axes_locator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't see how this change is needed? (doesn't hurt, but still?)

for ax in self.parasites]
bbs.append(super().get_tightbbox(renderer, call_axes_locator))
bbs.append(super().get_tightbbox(renderer,
call_axes_locator=call_axes_locator))
return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])


Expand Down
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletionslib/mpl_toolkits/tests/test_axes_grid1.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@
from mpl_toolkits.axes_grid1 import host_subplot
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.axes_grid1 import AxesGrid
from mpl_toolkits.axes_grid1 import ImageGrid
from mpl_toolkits.axes_grid1.inset_locator import (
zoomed_inset_axes,
mark_inset,
Expand DownExpand Up@@ -380,3 +381,28 @@ def test_anchored_direction_arrows_many_args():
sep_x=-0.06, sep_y=-0.08, back_length=0.1, head_width=9,
head_length=10, tail_width=5)
ax.add_artist(direction_arrows)


def test_axes_locatable_position():
fig, ax = plt.subplots()
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad='2%')
fig.canvas.draw()
assert np.isclose(cax.get_position(original=False).width,
0.03621495327102808)


@image_comparison(baseline_images=['image_grid'], extensions=['png'],
remove_text=True, style='mpl20',
savefig_kwarg={'bbox_inches': 'tight'})
def test_image_grid():
# test that image grid works with bbox_inches=tight.
im = np.arange(100)
im.shape = 10, 10

fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111, nrows_ncols=(2, 2), axes_pad=0.1)

for i in range(4):
grid[i].imshow(im)
grid[i].set_title('test {0}{0}'.format(i))

[8]ページ先頭

©2009-2025 Movatter.jp