Skip to content

Feat more advanced sharing of axes. #244

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

Closed
wants to merge 27 commits into from

Conversation

cvanelteren
Copy link
Contributor

Fixed issue where twinned axes reversed axis sharing: #233

@cvanelteren
Copy link
Contributor Author

cvanelteren commented Jun 2, 2025

Need to address some of the failing tests but otherwise looks good.

@cvanelteren
Copy link
Contributor Author

I think the issue is that the mapping from sharing and sharee is exactly inverted in UltraPlot compared to matplotlib. This is not nessarily an issue, except that we cannot toggle the tick_params individually. This is what needs to be addressed here to properly fix it. Not sure yet how tho.

@cvanelteren
Copy link
Contributor Author

I’m trying to track down a behavioral difference between UltraPlot and Matplotlib regarding axis sharing and tick label display.

In Matplotlib, the shared and sharee roles appear to be the inverse of how UltraPlot handles them—but this doesn't seem to be the root cause of the issue I'm seeing.

Here’s what I’ve found: in Matplotlib, we can control tick label visibility per subplot. For example, setting

ax[0, 0].tick_params(labeltop=True, labelright=True)

results in the following output:

Matplotlib example
image

However, doing the same in UltraPlot does not show the tick labels:

UltraPlot example
image

Now that I think about it, this might actually be due to how the shared axes are set up. In Matplotlib, the top-left subplot (ax[0, 0]) does not share its axis with any other subplot (i.e., its .sharex and .sharey are None). In UltraPlot, however, those attributes are not None—which might suppress the label rendering.

When I manually set the shared axes for the top-left subplot in UltraPlot to None, the tick labels appear as expected.

Could use your thoughts on this, @beckermr—does this sound like a difference in how the initial sharing is applied or propagated?

@beckermr
Copy link
Collaborator

beckermr commented Jun 2, 2025

TBH I don't know at all. :/

@cvanelteren
Copy link
Contributor Author

hmmm ok. We could revert the commit for now, but it is also broken in that state. I cannot directly see the difference that are apparent. I can at least state:

  • we are not overriding tick_params
  • labels become visible when _sharex/y is set to None
  • Reversing sharex or sharey will merely move the labels to the "other" set than is active currently but will not solve the issue (see comment above for reverse order)
  • somehow UltraPlot is forcing that labels are off and cannot be controlled by tick_params which is not the same as for matplotlib.
    Will look more into this issue, but progress may be slow.

@cvanelteren
Copy link
Contributor Author

Found the issue in _apply_axis_share

@cvanelteren
Copy link
Contributor Author

I need to move some logic there to the setup, and check whether it will affect downstream processing. But little later ;-)!

@cvanelteren
Copy link
Contributor Author

cvanelteren commented Jun 2, 2025

I believe I got it working 🥳.

The function _apply_axis_sharing was forcing the ticks to be off for all axes top and bottom for x and left an right for y. I moved this logic to the setup functions and I am using the same logic as is used for the GeoAxes to determine which labels should be on or off. This creates an additional benefit that the geoplots and cartesian plots end up having a similar feel (or at least is going to).

Note that with this change, we can now modify the axes post creation which prevents a weird disconnect with behavior under matplotlib and under ultraplot.

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Contributor Author

Need to move some code around, but this is starting to look good: the problem is identified and we can solve this.

@cvanelteren
Copy link
Contributor Author

cvanelteren commented Jun 3, 2025

I refactored the sharing and moved it into figure. I have in addition introduced some new functionality to utils for internal use. I further expanded the axes sharing to allow for subsharing depending on the axis type (geo, cartesian etc). It is in a rough state now and it drastically needs some tests, but I intend to move the sharing and turning on and off on label on figure creation, and or when all axes are formatted. This differs from the current implementation that forces everything on draw and limits the kinds of sharing that is allowed. It additionally creates a side effect where modifying singular subplots is not allowed.

@cvanelteren
Copy link
Contributor Author

Some tests are still failing, but most of the pieces are in place now. Just need to check that on creation the sharing is called at an appropriate time.

@cvanelteren
Copy link
Contributor Author

Need to fix an edge case where some plots are spanning another (or vice versa). For these cases the labels should be turned on.

@cvanelteren
Copy link
Contributor Author

cvanelteren commented Jun 3, 2025

I guess the best approach would be to convert the crawler into something that check ranges. Then if the range is exactly the same to the left or right, we drop the label, otherwise we keep them on (same for top and bottom).

@cvanelteren cvanelteren changed the title Fix twinned axes reversing sharing Feat more advanced sharing of axes. Jun 4, 2025
@cvanelteren cvanelteren added this to the v1.60 milestone Jun 11, 2025
@cvanelteren cvanelteren self-assigned this Jun 11, 2025
@cvanelteren cvanelteren added bug Something isn't working enhancement New feature or request labels Jun 11, 2025
@cvanelteren
Copy link
Contributor Author

Need to finalize this before I forget and become not merged in main.

the main issue is that ultraplot currently works flawlessly for sharing bottom and left labels but fails to work for top right labels on regular grids and non regular layouts.

I see the major issue can be encapsulated as:

  • in the apply sharing function, we force the labels for x or y to be off if we are sharing x or y, this needs to be undone if the axis is a border and potentially removing the labels from the not shared axis.

I initially tries to solve the issue by inverting the sharing pattern, but this does not solve the issue as it will cause strange interactions with twinned axes and furthermore, will not work if all the labels are on. This would imply that we copy the logic for sharing and introduce sharex_top and sharey_right or something similar.

@cvanelteren cvanelteren deleted the fix-twinned branch June 12, 2025 09:23
@cvanelteren cvanelteren restored the fix-twinned branch June 12, 2025 09:25
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