Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7229c5

Browse files
authored
Merge pull request #5 from eslothower/task3
Groundwork for task 3, plotting with function(x,y), test file for task 3, bug fixes
2 parents 028dd77 + 3f78f05 commit b7229c5

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,12 +3016,21 @@ def mouse_move(self, event):
30163016
self.set_message(self._mouse_event_to_message(event))
30173017

30183018
if callable(getattr(self, 'set_hover_message', None)):
3019-
def nonrect(x):
3020-
return not isinstance(x, Rectangle)
3021-
for a in self.canvas.figure.findobj(match=nonrect, include_self=False):
3022-
inside, prop = a.contains(event)
3019+
for a in self.canvas.figure.findobj(match=lambda x: not isinstance(x,
3020+
Rectangle), include_self=False):
3021+
inside = a.contains(event)
30233022
if inside:
3024-
self.set_hover_message(self._mouse_event_to_message(event))
3023+
if a.hoverable():
3024+
hover = a.get_hover()
3025+
if callable(hover):
3026+
newX, newY = hover(event)
3027+
(self.set_hover_message("modified x = " + str(newX)
3028+
+ " modified y = " +
3029+
str(newY) +
3030+
" Original coords: "
3031+
))
3032+
else:
3033+
self.set_hover_message(self._mouse_event_to_message(event))
30253034
else:
30263035
self.set_hover_message("")
30273036
break
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import matplotlib
2+
import matplotlib.pyplot as plt
3+
from numpy.random import rand
4+
matplotlib.use('tkagg')
5+
6+
7+
# Run this if it seems like your chanegs aren't being applied. If this does not
8+
# print something along the lines of:
9+
# 3.8.0.dev898+g0a062ed8bf.d20230506 /Users/eslothower/Desktop/matplotlib/lib/
10+
# matplotlib/__init__.py
11+
# then this means you did not set up matplotlib for development:
12+
# https://matplotlib.org/stable/devel/development_setup.html
13+
14+
# print(matplotlib.__version__, matplotlib.__file__)
15+
16+
fig, ax = plt.subplots()
17+
plt.ylabel('some numbers')
18+
19+
20+
def user_defined_function(event):
21+
return round(event.xdata * 10, 1), round(event.ydata + 3, 3)
22+
23+
ax.plot(rand(100), 'o', hover=user_defined_function)
24+
plt.show()

0 commit comments

Comments
 (0)