Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

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.

@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
Collaborator 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

@cvanelteren
Copy link
Collaborator Author

Thanks will have a careful look tomorrow and update you on the details to finalize this PR

@cvanelteren
Copy link
Collaborator Author

So I had to some time to settle back in and ready to pick this up again.

I think for the label sharing level, we should change the docs to state that it will share with the outermost labels. For left and bottom labels that would be the leftmost and bottomost, and for top and right it will be topmost and rightmost.

Now there are the edgecases where a plot is not flanked directly by another plot. In this case, I think it makes most sense to also add the labels there -- do you agree @beckermr?

This would mean that the code and docs would need to reflect this change, which won't affect dense grids but will more complex layouts.

@beckermr
Copy link
Collaborator

I agree in general unless the labels are duplicated like in the image above. In that case, we should keep only the one that applies to the full plot. This should be what I wrote above.

@cvanelteren
Copy link
Collaborator Author

Ok great will focus on fixing the PR and will ping you again for review.

@cvanelteren cvanelteren marked this pull request as draft July 31, 2025 06:45
@cvanelteren
Copy link
Collaborator Author

image These tests fails but require some input on what we allow. We are seeing that the outermost panel now has the ticks turned on. I think this makes sense as the panel belongs to a singular plot, but we may want to return to the old behavior.

Let me know what you think @beckermr

@beckermr
Copy link
Collaborator

I think for panels we should return to the old behavior.

@cvanelteren
Copy link
Collaborator Author

All green ;-)!

@cvanelteren cvanelteren requested a review from beckermr August 1, 2025 07:59
@cvanelteren cvanelteren marked this pull request as ready for review August 2, 2025 14:14
Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

One minor thing on a comment, but otherwise LGTM.

docs/subplots.py Outdated
# * ``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.
# nothing else. Labels will appear on the outermost plots. This implies that for left, and bottom labels (default) the labels will appear on the leftmost and bottommost subplots
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's split this comment across multiple lines.

@cvanelteren cvanelteren enabled auto-merge (squash) August 5, 2025 12:22
@cvanelteren cvanelteren merged commit 8f66423 into Ultraplot:main Aug 5, 2025
25 checks passed
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