-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Display cursor coordinates for all axes twinned with the current one. #25556
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
Conversation
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.
While I've not tested this i have some reservations concerning performance. format_coord
is called on mouse move and should be fast. Likely a worst-case scenario are 10x10 Axes without twinning, but using a Cursor so that delays become more apparent.
we should at least have an early return if there are no twins.
Sure, I added an early return for the twinless case. Edit: done as a separate commit: I switched Grouper so that it handles the ordering. |
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.
Just one typo.
This seems like a reasonable thing to do. I haven't tried to check the performance. Given that for a stream of mouse move events the twin lists and the transforms aren't going to change, there is considerable unnecessary work going on; but reducing it might be more trouble than it is worth.
Possible bike-shedding: change the joins from " / " to ", "? I think it would be more readable.
Did you try playing with it (e.g. Reducing the "duplicate" work seems not so easy without introducing some layers of caching and cache invalidation, which I'm not particularly keen to do. |
I just tested it out and it seemed pretty good performance wise to me. I would vote for pipe "|" instead of the slant for the separator. |
Sure, works for me. |
lib/matplotlib/cbook.py
Outdated
# For each item, we store (order_in_which_item_was_seen, group_of_item), which | ||
# lets __iter__ and get_siblings return items in the order in which they have | ||
# been seen. |
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.
Is this necessary? If I understand this correctly, you just encode the insertion order into the WeakKeyDictionary. Can't we rely on order preservation there? I've not tested this thoroughly but the internal data format WeakKeyDictionary.data
is a plain dict, which preserves order. So it should work as is. While WeakKeyDictionary has no official documentation whehter it preserves order or not, I assume CPython would not drop that de-facto feature without deprecation.
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.
Order preservation isn't really sufficient.
The mapping is storing {ax: [sibling0, sibling1, ...], ...} and what matters is that the list of siblings is sorted by the order in which they themselves occur in the mapping. So we could not explicitly store the index and instead sort the siblings by key=list(self._mapping).index
(taking advantage of order preservation) before returning them but that's less efficient.
lib/matplotlib/axes/_base.py
Outdated
" | ".join( | ||
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[0]) | ||
for ax in sorted(y_twins, key=attrgetter("zorder"))), | ||
" | ".join( | ||
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[1]) |
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.
Just realizing that this yield x=1 | 2 y=5
, which is not very readable. In particular |
creates a stronger visual separation than the space before y
.
I suggest to regroup into x, y pairs (even if that means
I suggest to either: x=1 ; 2 | y=5
.
Or regrouping into x, y pairs per Axes: x, y = (1, 5) | (2, 5)
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.
on the call we like x, y = (1, 5) | (4, 5)
best and lean to changing the non-twinned version to be x, y = (1, 3)
This was discussed during the call today. Looks like the preferred option is Tim's last one ( |
Meeting consensus: switch everything (regular and twinned) to @timhoffm's last suggestion above. |
🤣 Three of us posting notes about the meeting consensus. |
I implemented the |
Did a rebase, partially to rerun tests since logs were removed. Test failures are real, and related to the change at hand. |
Ping @anntzer on the above. |
Fixed. |
Python 3.12 error seems related. |
Fixed for real this time? Sorry for the back and forth. |
I also figured out that it would be much cleaner for Grouper to keep track of the ordering info in a separate dict rather than sticking everything in _mapping; moved that to a new _ordering dict instead. |
PR Summary
Closes #4284, closes #5506 (also: #2986 (comment)).
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst