-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow Artists to show pixel data in cursor display #3989
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
@@ -2791,6 +2791,12 @@ def mouse_move(self, event): | |||
except (ValueError, OverflowError): | |||
pass | |||
else: | |||
ax = event.inaxes | |||
artists = ax.artists + ax.images + ax.lines |
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.
Should also look at ax.collections
(that is where things like scatter live) and maybe ax.patches
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.
and the order should be ax.collections + ax.patches + ax.lines + ax.artists + ax.images
to match the order used for sorting out the rendering order in Axes.draw
(around https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_base.py#L1993 images are special cased around line 2030).
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.
They then get ordered by zorder anyway: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_base.py#L2036
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 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.
Ok then. So how to handle composite images? It does not seem feasible to recreate the composite every time.
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.
The AxesImage
could composite the specific pixel on demand.
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.
I think to first order, just ignore the compositing and use the top image.
The in-place compositing is only for some of the vector backends which can't do it them selves (ex pdf) to try and save space (so you don't have multiple overlapping images) but it leads to other bugs as all images get smashed to the same zorder relative to the other lines etc. In Agg (which backs all but 3 (gtkcairo, macsox and windows) of the interactive backends) the whole if _do_composite
block is skipped and the compsiting is taken care of at the c++ layer.
How's that? I noticed |
However, it looks like |
Probably worth having a top-level module for useful event handlers, which I think we greatly reduce the threshold to get people using the event system. @WeatherGod @joferkington thoughts? Yes to separate PR for re-ordering |
I think we do need to handle compositing. For instance, if I run this example, I get the Zdata for the overlay layer. How about just checking for |
Well, the more I think about it the more I agree that the top image should get priority. The canny value really is the point of the example. |
Added |
Do I still "need revision"? |
Looks good to me. I am a tad wary of the I would like @WeatherGod to weigh in. |
What do you mean "does not use |
Meaning it should be a static method? |
Either way I think it belongs in the class so it can be overridden. |
Yes, it is an instance method which does not refer to it's instance and I can't think of a use case where you would want to (but I may just have poor imagination). I thought about suggesting to move it to |
I'd worry that adding a |
This also needs an entry in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new |
Done. |
@matplotlib/developers Can this get eyes from someone else but me? This addresses a long standing and frequent feature request in a pleasingly general way. |
""" | ||
Get the zdata for a given event, as a string message | ||
""" | ||
return '' |
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.
Why do you want to use a string for this? Shouldn't "data" always be numeric?
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.
This allows the Artist
to control the display of numbers, similar to the existing ax.format_coord
.
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.
I agree with @efiring on this one. I can think of a lot of use cases (e.g. interactive sampling) where it would be very convenient to access a "raw" value. Returning a numerical value would make this method useful for a lot more than just display.
You already have a separate method for the formatting, so it's only slightly more verbose to flip the function calls on their head and make the displayed string using artist.format_zdata(artist.get_zdata())
. In my opinion, this would be a better approach overall.
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.
Ha! I originally meant to do that...
@joferkington again. Sorry to pester, but I see you are doing OSS stuff today and would like your feed back on this 😄 |
@tacaswell - Absolutely! Sorry I've been so out-of-touch with things lately, as well. |
df4ee01
to
bac8dff
Compare
ENH: Allow Artists to show pixel data in cursor display
Also adds implementation for
AxesImage
. Closes #3984.Inspired by mpldatacursor.