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

Skip to content

Fix tight-bbox computation of HostAxes. #30099

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def clear(self):
self._parent_axes.callbacks._connect_picklable(
"ylim_changed", self._sync_lims)

def get_axes_locator(self):
return self._parent_axes.get_axes_locator()

def pick(self, mouseevent):
# This most likely goes to Artist.pick (depending on axes_class given
# to the factory), which only handles pick events registered on the
Expand Down
23 changes: 22 additions & 1 deletion lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from matplotlib.backend_bases import MouseEvent
from matplotlib.colors import LogNorm
from matplotlib.patches import Circle, Ellipse
from matplotlib.transforms import Bbox, TransformedBbox
from matplotlib.transforms import Affine2D, Bbox, TransformedBbox
from matplotlib.testing.decorators import (
check_figures_equal, image_comparison, remove_ticks_and_titles)

Expand All @@ -26,6 +26,7 @@
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
from mpl_toolkits.axes_grid1.inset_locator import (
zoomed_inset_axes, mark_inset, inset_axes, BboxConnectorPatch)
from mpl_toolkits.axes_grid1.parasite_axes import HostAxes
import mpl_toolkits.axes_grid1.mpl_axes
import pytest

Expand Down Expand Up @@ -467,6 +468,26 @@ def test_gettightbbox():
[-17.7, -13.9, 7.2, 5.4])


def test_gettightbbox_parasite():
fig = plt.figure()

y0 = 0.3
horiz = [Size.Scaled(1.0)]
vert = [Size.Scaled(1.0)]
ax0_div = Divider(fig, [0.1, y0, 0.8, 0.2], horiz, vert)
ax1_div = Divider(fig, [0.1, 0.5, 0.8, 0.4], horiz, vert)

ax0 = fig.add_subplot(
xticks=[], yticks=[], axes_locator=ax0_div.new_locator(nx=0, ny=0))
ax1 = fig.add_subplot(
axes_class=HostAxes, axes_locator=ax1_div.new_locator(nx=0, ny=0))
aux_ax = ax1.get_aux_axes(Affine2D())

fig.canvas.draw()
rdr = fig.canvas.get_renderer()
assert rdr.get_canvas_width_height()[1] * y0 / fig.dpi == fig.get_tightbbox(rdr).y0


@pytest.mark.parametrize("click_on", ["big", "small"])
@pytest.mark.parametrize("big_on_axes,small_on_axes", [
("gca", "gca"),
Expand Down
Loading