Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9fd0b4

Browse files
authored
Merge pull request #30099 from anntzer/hatb
Fix tight-bbox computation of HostAxes.
2 parents 71e119b + 0b2c33e commit a9fd0b4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def clear(self):
2525
self._parent_axes.callbacks._connect_picklable(
2626
"ylim_changed", self._sync_lims)
2727

28+
def get_axes_locator(self):
29+
return self._parent_axes.get_axes_locator()
30+
2831
def pick(self, mouseevent):
2932
# This most likely goes to Artist.pick (depending on axes_class given
3033
# to the factory), which only handles pick events registered on the

lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from matplotlib.backend_bases import MouseEvent
1010
from matplotlib.colors import LogNorm
1111
from matplotlib.patches import Circle, Ellipse
12-
from matplotlib.transforms import Bbox, TransformedBbox
12+
from matplotlib.transforms import Affine2D, Bbox, TransformedBbox
1313
from matplotlib.testing.decorators import (
1414
check_figures_equal, image_comparison, remove_ticks_and_titles)
1515

@@ -26,6 +26,7 @@
2626
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
2727
from mpl_toolkits.axes_grid1.inset_locator import (
2828
zoomed_inset_axes, mark_inset, inset_axes, BboxConnectorPatch)
29+
from mpl_toolkits.axes_grid1.parasite_axes import HostAxes
2930
import mpl_toolkits.axes_grid1.mpl_axes
3031
import pytest
3132

@@ -467,6 +468,26 @@ def test_gettightbbox():
467468
[-17.7, -13.9, 7.2, 5.4])
468469

469470

471+
def test_gettightbbox_parasite():
472+
fig = plt.figure()
473+
474+
y0 = 0.3
475+
horiz = [Size.Scaled(1.0)]
476+
vert = [Size.Scaled(1.0)]
477+
ax0_div = Divider(fig, [0.1, y0, 0.8, 0.2], horiz, vert)
478+
ax1_div = Divider(fig, [0.1, 0.5, 0.8, 0.4], horiz, vert)
479+
480+
ax0 = fig.add_subplot(
481+
xticks=[], yticks=[], axes_locator=ax0_div.new_locator(nx=0, ny=0))
482+
ax1 = fig.add_subplot(
483+
axes_class=HostAxes, axes_locator=ax1_div.new_locator(nx=0, ny=0))
484+
aux_ax = ax1.get_aux_axes(Affine2D())
485+
486+
fig.canvas.draw()
487+
rdr = fig.canvas.get_renderer()
488+
assert rdr.get_canvas_width_height()[1] * y0 / fig.dpi == fig.get_tightbbox(rdr).y0
489+
490+
470491
@pytest.mark.parametrize("click_on", ["big", "small"])
471492
@pytest.mark.parametrize("big_on_axes,small_on_axes", [
472493
("gca", "gca"),

0 commit comments

Comments
 (0)