-
Notifications
You must be signed in to change notification settings - Fork 18
Test/update label sharing tests #372
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
Test/update label sharing tests #372
Conversation
This commit introduces a major refactoring of the tick and label sharing mechanism in UltraPlot. The previous implementation had complex and distributed logic for determining tick and label visibility, which was difficult to maintain and extend. This refactoring centralizes the logic within the `Figure` class, making it more robust and easier to understand. Key changes: - A new `_share_ticklabels` method in `Figure` now handles all tick label sharing. - The `_get_border_axes` method has been improved to be more accurate. - The `_Crawler` utility in `ultraplot/utils.py` has been rewritten to better handle complex layouts with panels and mixed axes types. - Redundant and complex logic has been removed from `CartesianAxes`, `GeoAxes`, and other modules.
This commit updates the test suite to align with the new tick and label sharing mechanism. Key changes: - Added `fig.canvas.draw()` calls in numerous tests to ensure that the new, deferred label sharing logic is triggered before assertions. - Updated assertions in tests for `CartesianAxes`, `GeoAxes`, and subplots to match the expected behavior of the refactored implementation. - Added new tests to cover more complex scenarios with panels and mixed axes types.
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
beckermr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between this PR and the other one that is similar?
|
The following tests need a closer look:
Some of these cases look like bugs. Others might be the desired outcome. I don't know which is which. |
|
Thanks for the careful review @beckermr! I think the ticks are related to the axes limits not being shared. Not sure how that changed -- but will get to the bottom of this. The tick params for the axis I fixed locally. Will check the final ones and recheck. After this I will get back to you. |
|
Weird I set the limits explicitly in the function |
|
Looking better! What should we decide on |
|
I took a look again. I see the following:
Yes. I'd say if the main axis is a geo axis, then the panel should have tick labels on since its axis is not shared. |
|
For fig, axs = uplt.subplots(ncols=2, share=True, refwidth=1.5, includepanels=False)
axs.panel("left", share=False)
fig.format(ylabel="ylabel", xlabel="xlabel")The logic for the current panel for the geo would need to change if we want that to be off for the test that is currently failing. Right now it will check if it is on a border but will automatically draw it for right axes; I am fine with it as is, as the default right now also puts these ticks on. However, it may make more sense to make it dependent on the main axis in general. Since in this case all ticks are off, it should also be off for the panel; but open to both tbh. |
beckermr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few unittest failures, but otherwise, LGTM!
|
Found the issue with the geo labels; |
|
What is this error on MPL 39? |
|
The key labelling changed in mpl 3.10; I thought I provided a fix for this with a translation function. Will carefully examine. Still ironing out some odd edge cases |
|
Will add some more tests tomorrow. Every combination is passing on the tests now indicating that the labels are correctly used internally. May also change how the private conversion handles directly by making it available as a global var. A bit annoying to make this dual compatibility. |
|
I think I added sufficient number of tests now to make this merge. I will wait for the tests to finish. I updated the text on top for internal reference so we can track what changed exactly. As most of the stuff is in wards facing it is key to keep track of what we changed so we don't get lost -- as I did many times in this PR. I think the sharing is more robust for the ticks now and allows for flexible sharing. I will turn to #373 as that one follows this PR and probable needs updating. |

The previous implementation had complex and distributed logic for determining tick and label visibility, which was difficult to maintain and extend. This refactoring centralizes the logic within the
Figureclass, making it more robust and easier to understand.Summary
Files changed
_share_ticklabelsinto smaller helpers:_label_key_map(): computes version-dependent label keys for tick_params._group_axes_by_axis(axes, axis): groups axes by row (x) or column (y)._compute_baseline_tick_state(group_axes, axis, label_keys): builds baseline ticklabel state from main axes only; warns on unsupported/mixed types._apply_border_mask(axi, baseline, sides, outer_axes): enforces figure borders and suppresses opposite panel sides; uses per-axis_label_key._effective_share_level(axi, axis, sides): computes effective share level considering panel groups and neighbors; checks both relevant sides (fixes prior “last side wins” leak)._set_ticklabel_state(axi, axis, state): applies state to cartesian via set_tick_params (with x/y-to-bool cleanup) or to geo via_toggle_gridliner_labels.sideafter iteration; share-level promotion now checks all relevant sides for the given axis._label_keymapping when reading/writing tick_paramsax.xaxis.set_tick_params(labeltop=False)withax.xaxis.set_tick_params(**{ax._label_key("labeltop"): False})(and similarly forlabelbottom,labelleft,labelright).pax._label_key(...).ax._label_key(...)forget_tick_params()[...]._apply_auto_share():self._panel_sharex_group = Trueso the main axes is included in the x-panel group even without bottom panels.self._panel_sharey_group = Trueso the main axes is included in the y-panel group even without left panels.Behavioral notes
_label_keyto maplabeltop/labelbottomtolabelright/labelleftas needed.stalesemantics preserved.User-visible impact