Skip to content

Hotfix panel #238

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

Merged
merged 35 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fdaeed4
simplified logic and basing reference on original grid
cvanelteren May 27, 2025
ff69863
rm print statements
cvanelteren May 27, 2025
6047368
spelling
cvanelteren May 27, 2025
1d8df56
Update ultraplot/figure.py
cvanelteren May 27, 2025
4926ada
do more comprehensive checking
cvanelteren May 27, 2025
7715b1e
rm debug
cvanelteren May 27, 2025
85f175e
add some reasoning
cvanelteren May 27, 2025
5bc9433
fixed
cvanelteren May 29, 2025
1b8baf9
add a stale check
cvanelteren May 29, 2025
8fe9546
compound tests and check for the failure
cvanelteren May 29, 2025
1fc675d
fixed missing functions in grid
cvanelteren May 29, 2025
8f12ec7
need to fix test
cvanelteren May 29, 2025
889a911
update calls
cvanelteren May 29, 2025
aad06c3
update tests
cvanelteren May 29, 2025
da5ac84
Merge branch 'main' into hotfix-get_border_axes
cvanelteren May 30, 2025
de46b46
formatting restored to defaults
cvanelteren May 30, 2025
072bb6c
don't adjust labels when not sharing
cvanelteren May 30, 2025
3c26827
tests pass -- some expected failures
cvanelteren May 30, 2025
b19e77a
Merge branch 'main' into hotfix-get_border_axes
cvanelteren May 30, 2025
61f427e
rm debug statements
cvanelteren May 30, 2025
c37cbc2
fix test
cvanelteren May 30, 2025
d55cd02
Merge branch 'hotfix-get_border_axes' into hotfix_panel
cvanelteren May 30, 2025
b931867
added tests
cvanelteren May 30, 2025
f2ee2cc
updated test to check for sharing of panels
cvanelteren May 30, 2025
8863f70
update test
cvanelteren May 30, 2025
0c8a608
update test
cvanelteren May 30, 2025
aa92a25
Update ultraplot/tests/test_geographic.py
cvanelteren May 30, 2025
f3432c4
rm unnecessary funcs
cvanelteren May 30, 2025
e2bf22c
Merge branch 'main' into hotfix_panel
cvanelteren Jun 1, 2025
ea1c34c
Deprecate basemap (#243)
cvanelteren Jun 1, 2025
b060516
Hotfix get_border_axes (#236)
cvanelteren Jun 2, 2025
c5dd66e
Merge branch 'main' into hotfix_panel
cvanelteren Jun 2, 2025
97b4941
refactor panel_group_member
cvanelteren Jun 2, 2025
68b76c2
mv logic to base
cvanelteren Jun 2, 2025
5573372
mv to the correct spot
cvanelteren Jun 2, 2025
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
37 changes: 37 additions & 0 deletions ultraplot/axes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,43 @@ def set_prop_cycle(self, *args, **kwargs):
cycle = self._active_cycle = constructor.Cycle(*args, **kwargs)
return super().set_prop_cycle(cycle) # set the property cycler after validation

def _is_panel_group_member(self, other: "Axes") -> bool:
"""
Determine if the current axes and another axes belong to the same panel group.

Two axes belong to the same panel group if any of the following is true:
1. One axis is the parent of the other
2. Both axes are panels sharing the same parent

Parameters
----------
other : Axes
The other axes to compare with

Returns
-------
bool
True if both axes belong to the same panel group, False otherwise
"""
# Case 1: self is a panel of other (other is the parent)
if self._panel_parent is other:
return True

# Case 2: other is a panel of self (self is the parent)
if other._panel_parent is self:
return True

# Case 3: both are panels of the same parent
if (
self._panel_parent
and other._panel_parent
and self._panel_parent is other._panel_parent
):
return True

# Not in the same panel group
return False

@docstring._snippet_manager
def inset(self, *args, **kwargs):
"""
Expand Down
12 changes: 0 additions & 12 deletions ultraplot/axes/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,6 @@ def _get_spine_side(self, s, loc):
)
return side

def _is_panel_group_member(self, other):
"""
Return whether the axes belong in a panel sharing stack..
"""
return (
self._panel_parent is other # other is child panel
or other._panel_parent is self # other is main subplot
or other._panel_parent
and self._panel_parent # ...
and other._panel_parent is self._panel_parent # other is sibling panel
)

def _sharex_limits(self, sharex):
"""
Safely share limits and tickers without resetting things.
Expand Down
2 changes: 1 addition & 1 deletion ultraplot/axes/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def __share_axis_setup(
limits: bool,
):
level = getattr(self.figure, f"_share{which}")
if getattr(self, f"_panel_share{which}_group") and self.is_panel_group_member(
if getattr(self, f"_panel_share{which}_group") and self._is_panel_group_member(
other
):
level = 3
Expand Down
74 changes: 74 additions & 0 deletions ultraplot/tests/test_geographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,77 @@ def test_check_tricontourf():
assert "transform" in mocked.call_args.kwargs
assert isinstance(mocked.call_args.kwargs["transform"], ccrs.PlateCarree)
uplt.close(fig)


def test_panels_geo():
fig, ax = uplt.subplots(proj="cyl")
ax.format(labels=True)
for dir in "top bottom right left".split():
pax = ax.panel_axes(dir)
match dir:
case "top":
assert len(pax.get_xticklabels()) > 0
assert len(pax.get_yticklabels()) > 0
case "bottom":
assert len(pax.get_xticklabels()) > 0
assert len(pax.get_yticklabels()) > 0
case "left":
assert len(pax.get_xticklabels()) > 0
assert len(pax.get_yticklabels()) > 0
case "right":
assert len(pax.get_xticklabels()) > 0
assert len(pax.get_yticklabels()) > 0


@pytest.mark.mpl_image_compare
def test_geo_with_panels():
"""
We are allowed to add panels in GeoPlots
"""
# Define coordinates
lat = np.linspace(-90, 90, 180)
lon = np.linspace(-180, 180, 360)
time = np.arange(2000, 2005)
lon_grid, lat_grid = np.meshgrid(lon, lat)

# Zoomed region elevation (Asia region)
lat_zoom = np.linspace(0, 60, 60)
lon_zoom = np.linspace(60, 180, 120)
lz, lz_grid = np.meshgrid(lon_zoom, lat_zoom)

elevation = (
2000 * np.exp(-((lz - 90) ** 2 + (lz_grid - 30) ** 2) / 400)
+ 1000 * np.exp(-((lz - 120) ** 2 + (lz_grid - 45) ** 2) / 225)
+ np.random.normal(0, 100, lz.shape)
)
elevation = np.clip(elevation, 0, 4000)

fig, ax = uplt.subplots(nrows=2, proj="cyl")
pax = ax[0].panel("r")
pax.barh(lat_zoom, elevation.sum(axis=1))
pax = ax[1].panel("r")
pax.barh(lat_zoom - 30, elevation.sum(axis=1))
ax[0].pcolormesh(
lon_zoom,
lat_zoom,
elevation,
cmap="bilbao",
colorbar="t",
colorbar_kw=dict(
align="l",
length=0.5,
),
)
ax[1].pcolormesh(
lon_zoom,
lat_zoom - 30,
elevation,
cmap="glacial",
colorbar="t",
colorbar_kw=dict(
align="r",
length=0.5,
),
)
ax.format(oceancolor="blue", coast=True)
return fig