Skip to content

Commit e6b1bc6

Browse files
cvanelterenbeckermrCopilot
authored
[Feature add] Share Axes in GeoPlot + bug fixes (#159)
- Added ability to share GeoAxes - Fixed numerous bugs regarding ticks on GeoAxes - Backend allows for sharing and unsharing axes. --------- Co-authored-by: Matthew R. Becker <beckermr@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ff5cd9d commit e6b1bc6

11 files changed

+1408
-61
lines changed

ultraplot/axes/base.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,37 @@ def _range_tightbbox(self, s):
24542454
else:
24552455
return bbox.ymin, bbox.ymax
24562456

2457+
def _unshare(self, *, which: str):
2458+
"""
2459+
Remove this Axes from the shared Grouper for the given axis ('x', 'y', 'z', or 'view').
2460+
Note this isolates the axis and does not preserve the transitivity of sharing.
2461+
"""
2462+
if which not in self._shared_axes:
2463+
warnings._warn_ultraplot(f"Axis {which} is not shared")
2464+
return
2465+
if which in "xy":
2466+
setattr(self, f"_share{which}", None) # essential
2467+
# Note _scale is also set when calling sharex or y.
2468+
# I think it is fine to leave it as otherwise we would
2469+
# need to determine the scale, which may get messy.
2470+
2471+
grouper = self._shared_axes[which]
2472+
siblings = list(grouper.get_siblings(self))
2473+
for sibling in siblings:
2474+
if sibling is not self:
2475+
# Unshare by removing them from the grouper
2476+
grouper.remove(sibling)
2477+
sibling._shared_axes[which].remove(self)
2478+
# To be safe let's remove this
2479+
self._shared_axes[which].remove(sibling)
2480+
if which in "xy":
2481+
setattr(sibling, f"_share{which}", None)
2482+
this_ax = getattr(self, f"{which}axis")
2483+
sib_ax = getattr(sibling, f"{which}axis")
2484+
# Reset formatters
2485+
this_ax.major = copy.deepcopy(this_ax.major)
2486+
this_ax.minor = copy.deepcopy(this_ax.minor)
2487+
24572488
def _sharex_setup(self, sharex, **kwargs):
24582489
"""
24592490
Configure x-axis sharing for panels. See also `~CartesianAxes._sharex_setup`.

0 commit comments

Comments
 (0)