Skip to content

Commit 736d53e

Browse files
committed
final style fixes
1 parent 599948e commit 736d53e

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,25 +3016,24 @@ def _nonrect(self, x):
30163016

30173017
def _tooltip_list(self, event, hover):
30183018
import matplotlib.pyplot as plt
3019-
if event.xdata and event.ydata:
3020-
lines = plt.gca().get_lines()
3021-
num_of_points = 0
3019+
lines = plt.gca().get_lines()
3020+
num_of_points = 0
3021+
for line in lines:
3022+
num_of_points += 1
3023+
if num_of_points >= len(hover):
3024+
raise ValueError("""Number of data points
3025+
does not match up with number of labels""")
3026+
else:
3027+
mouse_x = event.xdata
3028+
mouse_y = event.ydata
30223029
for line in lines:
3023-
num_of_points += 1
3024-
if num_of_points >= len(hover):
3025-
raise ValueError("""Number of data points
3026-
does not match up with number of labels""")
3027-
else:
3028-
mouse_x = event.xdata
3029-
mouse_y = event.ydata
3030-
for line in lines:
3031-
x_data = line.get_xdata()
3032-
y_data = line.get_ydata()
3033-
for i in range(len(x_data)):
3034-
distance = ((event.xdata - x_data[i])**2
3035-
+ (event.ydata - y_data[i])**2)**0.5
3036-
if distance < 0.05:
3037-
return "Data Label: " + hover[i]
3030+
x_data = line.get_xdata()
3031+
y_data = line.get_ydata()
3032+
for i in range(len(x_data)):
3033+
distance = ((event.xdata - x_data[i])**2
3034+
+ (event.ydata - y_data[i])**2)**0.5
3035+
if distance < 0.05:
3036+
return "Data Label: " + hover[i]
30383037

30393038
def mouse_move(self, event):
30403039
self._update_cursor(event)

lib/matplotlib/tests/test_toolkit.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
matplotlib.use('tkagg')
55

66
fig, ax = plt.subplots()
7-
plt.ylabel('some numbers')
87

98

109
def user_defined_function(event):
11-
if event.xdata and event.ydata:
12-
x, y = round(event.xdata * 10, 1), round(event.ydata + 3, 3)
13-
return f'({x}, {y})'
14-
return ''
10+
x, y = round(event.xdata * 10, 1), round(event.ydata + 3, 3)
11+
return f'({x}, {y})'
1512

1613

1714
ax.plot(rand(100), 'o', hover=user_defined_function)
@@ -21,7 +18,6 @@ def user_defined_function(event):
2118
# Alternative test for testing out string literals as tooltips:
2219

2320
fig, ax = plt.subplots()
24-
plt.ylabel('some numbers')
2521

2622
ax.plot(rand(3), 'o', hover=['London', 'Paris', 'Barcelona'])
2723
plt.show()

0 commit comments

Comments
 (0)