Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f93091e

Browse filesBrowse files
Simplified search for plot datat index matching mouse cursor position
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent 5319e89 commit f93091e
Copy full SHA for f93091e

File tree

Expand file treeCollapse file tree

1 file changed

+10
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-16
lines changed

‎examples/widgets/annotated_cursor.py

Copy file name to clipboardExpand all lines: examples/widgets/annotated_cursor.py
+10-16Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,16 @@ def setpos(self, xpos, ypos):
240240
raise ValueError(f"The data axis specifier {self.dataaxis} should "
241241
f"be 'x' or 'y'")
242242

243-
# If position is valid
244-
if pos is not None:
245-
# And in valid plot data range
246-
if pos >= lim[0] and pos <= lim[-1]:
247-
# Convert given positon to numpy array,
248-
# so numpy function can be used.
249-
findme = np.array([pos])
250-
# Find closest x value in sorted x vector.
251-
# This is the code line,
252-
# which requires the plotted data to be sorted.
253-
index = np.searchsorted(data, findme)
254-
# Return none, if this index is out of range.
255-
if (index < 0) or (index >= len(data)):
256-
return None
257-
# Return plot point as tuple.
258-
return (xdata[index][0], ydata[index][0])
243+
# If position is valid and in valid plot data range.
244+
if pos is not None and lim[0] <= pos <= lim[-1]:
245+
# Find closest x value in sorted x vector.
246+
# This requires the plotted data to be sorted.
247+
index = np.searchsorted(data, pos)
248+
# Return none, if this index is out of range.
249+
if index < 0 or index >= len(data):
250+
return None
251+
# Return plot point as tuple.
252+
return (xdata[index][0], ydata[index][0])
259253

260254
# Return none if there is no good related point for this x position.
261255
return None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.