8000 Document Artist.get_cursor_data · matplotlib/matplotlib@c7e4006 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7e4006

Browse files
committed
Document Artist.get_cursor_data
1 parent b96fb6f commit c7e4006

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/matplotlib/artist.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,44 @@ def matchfunc(x):
11141114

11151115
def get_cursor_data(self, event):
11161116
"""
1117-
Get the cursor data for a given event.
1117+
Return the cursor data for a given event.
1118+
1119+
.. note::
1120+
This is part of the internal API. As an end-user of Matplotlib
1121+
you will most likely not call this method yourself.
1122+
1123+
Cursor data can be used by Artists to provide additional context
1124+
information for a given event. The default implementation just returns
1125+
*None*.
1126+
1127+
Subclasses can override the method and return arbitrary data. However,
1128+
when doing so, they must ensure that `.format_cursor_data` can convert
1129+
the data to a string representation.
1130+
1131+
The only current use case is displaying the z-value of an `.AxesImage`
1132+
in the status bar of a plot window, while moving the mouse.
1133+
1134+
See Also
1135+
--------
1136+
format_cursor_data
1137+
11181138
"""
11191139
return None
11201140

11211141
def format_cursor_data(self, data):
11221142
"""
1123-
Return *cursor data* string formatted.
1143+
Return a string representation of *data*.
1144+
1145+
.. note::
1146+
This is part of the internal API. As an end-user of Matplotlib
1147+
you will most likely not call this method yourself.
1148+
1149+
The default implementation converts ints and floats and arrays of ints
1150+
and floats into a comma-separated string.
1151+
1152+
See Also
1153+
--------
1154+
get_cursor_data
11241155
"""
11251156
try:
11261157
data[0]

lib/matplotlib/image.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,14 @@ def get_extent(self):
881881
return (-0.5, numcols-0.5, -0.5, numrows-0.5)
882882

883883
def get_cursor_data(self, event):
884-
"""Get the cursor data for a given event"""
884+
"""
885+
Return the image value at the event position or *None* if the event is
886+
outside the image.
887+
888+
See Also
889+
--------
890+
matplotlib.artist.Artist.get_cursor_data
891+
"""
885892
xmin, xmax, ymin, ymax = self.get_extent()
886893
if self.origin == 'upper':
887894
ymin, ymax = ymax, ymin
@@ -1142,7 +1149,7 @@ def set_array(self, *args):
11421149
raise NotImplementedError('Method not supported')
11431150

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

0 commit comments

Comments
 (0)
0