8000 Document Artist.get_cursor_data by timhoffm · Pull Request #12427 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Document Artist.get_cursor_data #12427

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 1 commit into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 35 additions & 2 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,46 @@ def matchfunc(x):

def get_cursor_data(self, event):
"""
Get the cursor data for a given event.
Return the cursor data for a given event.

.. note::
This method is intended to be overridden by artist subclasses
(or monkeypatched). As an end-user of Matplotlib you will most
likely not call this method yourself.

Cursor data can be used by Artists to provide additional context
information for a given event. The default implementation just returns
*None*.

Subclasses can override the method and return arbitrary data. However,
when doing so, they must ensure that `.format_cursor_data` can convert
the data to a string representation.

The only current use case is displaying the z-value of an `.AxesImage`
in the status bar of a plot window, while moving the mouse.

See Also
--------
format_cursor_data

"""
return None

def format_cursor_data(self, data):
"""
Return *cursor data* string formatted.
Return a string representation of *data*.

.. note::
This method is intended to be overridden by artist subclasses
(or monkeypatched). As an end-user of Matplotlib you will most
likely not call this method yourself.

The default implementation converts ints and floats and arrays of ints
and floats into a comma-separated string enclosed in square brackets.

See Also
--------
get_cursor_data
"""
try:
data[0]
Expand Down
11 changes: 9 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,14 @@ def get_extent(self):
return (-0.5, numcols-0.5, -0.5, numrows-0.5)

def get_cursor_data(self, event):
"""Get the cursor data for a given event"""
"""
Return the image value at the event position or *None* if the event is
outside the image.

See Also
--------
matplotlib.artist.Artist.get_cursor_data
"""
xmin, xmax, ymin, ymax = self.get_extent()
if self.origin == 'upper':
ymin, ymax = ymax, ymin
Expand Down Expand Up @@ -1142,7 +1149,7 @@ def set_array(self, *args):
raise NotImplementedError('Method not supported')

def get_cursor_data(self, event):
"""Get the cursor data for a given event"""
# docstring inherited
x, y = event.xdata, event.ydata
if (x < self._Ax[0] or x > self._Ax[-1] or
y < self._Ay[0] or y > self._Ay[-1]):
Expand Down
0