8000 Allow Artists to show pixel data in cursor display by blink1073 · Pull Request #3989 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 26 commits into from
May 24, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34854db
Add the ability for artists to display zdata in cursor
blink1073 Jan 9, 2015
7e0d1ca
PEP8 fix
blink1073 Jan 9, 2015
97640da
Another Pep8 fix
blink1073 Jan 10, 2015
139d820
Pep8: fix trailing whitespace
blink1073 Jan 10, 2015
17e4211
Style update
blink1073 Jan 10, 2015
fcda62b
Standardize the hit test and zordering
blink1073 Jan 19, 2015
8ea9504
Fix the artist sorting behaviour
blink1073 Jan 19, 2015
02456b8
Fix syntax error
blink1073 Jan 19, 2015
641304c
Specify hitlist on axes instead of figure
blink1073 Jan 19, 2015
3f20d3a
Put get_zdata on the correct class
blink1073 Jan 19, 2015
5850150
Ignore the axes patch
blink1073 Jan 19, 2015
88b56be
Create new function to format zdata
blink1073 Jan 19, 2015
aece695
Clean up string formatting
blink1073 Jan 19, 2015
07745c8
Add a whats new blurb.
blink1073 Jan 20, 2015
7626394
Add a test for image cursor data
blink1073 Feb 21, 2015
7b0b6b1
Rename to get_pixel_data and return raw data
blink1073 Feb 21, 2015
f5ff73f
Update the whats new
blink1073 Feb 21, 2015
ea565c6
Fix name of method
blink1073 Feb 21, 2015
1429206
Fix default pixel data and handle no pixel data
blink1073 Feb 21, 2015
e62b0e3
Update test for new method name
blink1073 Feb 21, 2015
34b4df4
Simplify transform
blink1073 Feb 21, 2015
8f266a1
Update display
blink1073 Feb 21, 2015
70983ff
Simplify format_pixel_data
blink1073 Mar 8, 2015
cd0e52b
Update name to cursor_data
blink1073 Mar 8, 2015
8ce3a6f
Move artist sort to within if block
blink1073 Mar 10, 2015
bac8dff
Fix method name in cursor_test
blink1073 Mar 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename to get_pixel_data and return raw data
  • Loading branch information
blink1073 committed Mar 17, 2015
commit 7b0b6b1f5536a508df08c2f741f5ec3c8f4cda11
20 changes: 10 additions & 10 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,26 +903,26 @@ def matchfunc(x):
artists.append(self)
return artists

def get_zdata(self, event):
def get_pixel_data(self, event):
"""
Get the zdata for a given event, as a string message
Get the pixel data for a given event.
"""
return ''
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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...


def format_zdata(self, z):
def format_pixel_data(self, data):
"""
Return *z* string formatted.
Return *pixel data* string formatted.
"""
try:
is_int = isinstance(z[0], int)
is_int = isinstance(data[0], int)
except (TypeError, IndexError):
is_int = isinstance(z, int)
z = [z]
is_int = isinstance(data, int)
data = [data]
if is_i 8000 nt:
z = ', '.join(item for item in z)
data = ', '.join(item for item in data)
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this working? I don't think is_int is ever being set as this line should not work - joinshould give a TypeError if it gets a sequence of int and not a sequence of string. Try data=[1, 2, 3]; data = ', '.join(item for item in data) (BTW, you could have just used data instead of item for item in data).

I suspect what is going on in your example is that a numpy array is being given and is_int is being set to False and the else condition is always used. That being the case, then you might as well not even test for int and just use the {:0.3g} formatter in all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, simplified.

else:
z = ', '.join('{:0.3g}'.format(item) for item in z)
return z
data = ', '.join('{:0.3g}'.format(item) for item in data)
return data


class ArtistInspector(object):
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,9 @@ def mouse_move(self, event):
artists.remove(event.inaxes.patch)
artists.sort(key=lambda x: x.zorder)
if artists:
Copy link
Contributor

Choose a reason for hiding this comment

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

Something seems odd about checking if artists is empty after sorting the list. I know (provided artists is a list) it won't error out, but still seems to me that the sort should go ahead and move within the if block.

Also, +1 for removing ye olden style DSU in favor of sort(key=).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, done.

s += artists[-1].get_zdata(event)
a = artists[-1]
data = a.get_cursor_data(event)
s += 'data= %s' % a.format_cursor_data(data)
if len(self.mode):
self.set_message('%s, %s' % (self.mode, s))
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def get_zdata(self, event):
y, x = event.ydata, event.xdata
i, j = trans.transform_point([y, x]).astype(int)
z = arr[i, j]
return 'z=%s' % self.format_zdata(z)
return z


class NonUniformImage(AxesImage):
Expand Down
0