Skip to content

feat: advanced axis sharing refactor + enhancements #256

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 80 commits into
base: main
Choose a base branch
from

Conversation

cvanelteren
Copy link
Contributor

Rename of #244

One of UltraPlot's most powerful features is the ability to do advanced axis sharing. The current implementation works well for bottom and left label sharing, but failed in sharing labels for top right labels. This PR addresses this problem while at the same time allowing for sharing axes with more complex layouts.

@cvanelteren
Copy link
Contributor Author

At least the network error is gone now 🥳

@cvanelteren
Copy link
Contributor Author

Figured out the problem see #274

@beckermr
Copy link
Collaborator

OK I can proceed on review of this PR.

@cvanelteren
Copy link
Contributor Author

Think the tests that fail are looking good last I checked (prior to latest merge). The issue addresses in #233 is not completely fixed since the partial reversal that happened.

@cvanelteren
Copy link
Contributor Author

Will need to look at layout1 for test_label_sharing_top_right but not no as its getting late ;-)

@@ -904,6 +907,185 @@ def units(
return result[0] if singleton else result


def _get_subplot_layout(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole function needs many more comments. What is axis_type = 1 and why is it hard coded?

@beckermr
Copy link
Collaborator

beckermr commented Jul 7, 2025

@cvanelteren the test failures here need looking at

@cvanelteren
Copy link
Contributor Author

Will have a closer look tomorrow. For me these tests need TLC:

  • test_inset_basic
  • test_share_all_basic

@beckermr
Copy link
Collaborator

beckermr commented Jul 7, 2025

I see these as well

FAILED ultraplot/tests/test_subplots.py::test_label_sharing_top_right[layout0] - AssertionError: assert False == True
 +  where False = _is_ticklabel_on('labeltop')
 +    where _is_ticklabel_on = CartesianAxes(index=(0, 0), number=1)._is_ticklabel_on
FAILED ultraplot/tests/test_subplots.py::test_label_sharing_top_right[layout1] - AssertionError: assert False == True
 +  where False = _is_ticklabel_on('labelright')
 +    where _is_ticklabel_on = CartesianAxes(index=(0, 0), number=1)._is_ticklabel_on

@cvanelteren
Copy link
Contributor Author

I see these as well

FAILED ultraplot/tests/test_subplots.py::test_label_sharing_top_right[layout0] - AssertionError: assert False == True
 +  where False = _is_ticklabel_on('labeltop')
 +    where _is_ticklabel_on = CartesianAxes(index=(0, 0), number=1)._is_ticklabel_on
FAILED ultraplot/tests/test_subplots.py::test_label_sharing_top_right[layout1] - AssertionError: assert False == True
 +  where False = _is_ticklabel_on('labelright')
 +    where _is_ticklabel_on = CartesianAxes(index=(0, 0), number=1)._is_ticklabel_on

For that particular plot, I need some input. The test produces:
image
The issue is in how the axis sharing is applied. For the middle plot it is not sharing any axis so it turns the top and right label on. For the bottom left and right, it is sharing x with the top plots and hence is not showing the labels on the top. Similarly the plot on the top left is sharing with the top right.

The current logic is looking for border that are either the edges of the subplot grid or when a plot is not adjacent to another plot (in that direction). The new border detection logic is correctly identifying the borders of each subplot, but it is overriden by the apply_axis_sharing logic.

This particular layout, lends itself most to just turning the axis sharing off (I think), but we should allow users to still perform the sharing. This would mean that we should adjust the test accordingly, or adjust the apply axis sharing logic. Not sure where to proceed here.

@beckermr
Copy link
Collaborator

OK I lost track of this PR. Sorry.

What is the share level for this test? The docs currently say

Supporting five sharing “levels”. These values can be passed to sharex, sharey, or share, or assigned to rc['subplots.share']. The levels are defined as follows:

  • False or 0: Axis sharing is disabled.

  • 'labels', 'labs', or 1: Axis labels are shared, but nothing else. Labels will appear on the leftmost and bottommost subplots.

  • 'limits', 'lims', or 2: Same as 1, but axis limits, axis scales, and major and minor tick locations and formatting are also shared.

  • True or 3 (default): Same as 2, but axis tick labels are also shared. Tick labels will appear on the leftmost and bottommost subplots.

  • 'all' or 4: Same as 3, but axis limits, axis scales, and axis ticks are shared even between subplots not in the same row or column.

For the middle panel in each sharing level we should have

  • level 0: display limits+ticks+labels
  • level 1: display limits+ticks, no axis label
  • level 2: display limits+ticks, no axis label
  • level 3: display limits+ticks because it is the outer most panel for both vertical and horizontal direction for its row+column, no axis label
  • level 4: same as level 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants