8000 Fix cursor_demo wrt. Line2D.set_x/ydata not accepting scalars anymore. · matplotlib/matplotlib@bb1e1a0 · GitHub
[go: up one dir, main page]

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 bb1e1a0

Browse files
committed
Fix cursor_demo wrt. Line2D.set_x/ydata not accepting scalars anymore.
Trying to run the example prior to the PR would result in exceptions being thrown on mouse moves.
1 parent 546b9fc commit bb1e1a0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

examples/event_handling/cursor_demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def on_mouse_move(self, event):
5656
self.set_cross_hair_visible(True)
5757
x, y = event.xdata, event.ydata
5858
# update the line positions
59-
self.horizontal_line.set_ydata(y)
60-
self.vertical_line.set_xdata(x)
59+
self.horizontal_line.set_ydata([y])
60+
self.vertical_line.set_xdata([x])
6161
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
6262
self.ax.figure.canvas.draw()
6363

@@ -132,8 +132,8 @@ def on_mouse_move(self, event):
132132
self.set_cross_hair_visible(True)
133133
# update the line positions
134134
x, y = event.xdata, event.ydata
135-
self.horizontal_line.set_ydata(y)
136-
self.vertical_line.set_xdata(x)
135+
self.horizontal_line.set_ydata([y])
136+
self.vertical_line.set_xdata([x])
137137
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
138138

139139
self.ax.figure.canvas.restore_region(self.background)
@@ -204,8 +204,8 @@ def on_mouse_move(self, event):
204204
x = self.x[index]
205205
y = self.y[index]
206206
# update the line positions
207-
self.horizontal_line.set_ydata(y)
208-
self.vertical_line.set_xdata(x)
207+
self.horizontal_line.set_ydata([y])
208+
self.vertical_line.set_xdata([x])
209209
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
210210
self.ax.figure.canvas.draw()
211211

examples/widgets/annotated_cursor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
The figure related to this example does not show the cursor, because that
1919
figure is automatically created in a build queue, where the first mouse
2020
movement, which triggers the cursor creation, is missing.
21-
2221
"""
22+
2323
from matplotlib.widgets import Cursor
2424
import numpy as np
2525
import matplotlib.pyplot as plt
2626

2727

2828
class AnnotatedCursor(Cursor):
2929
"""
30-
A crosshair cursor like `~matplotlib.widgets.Cursor` with a text showing \
30+
A crosshair cursor like `~matplotlib.widgets.Cursor` with a text showing
3131
the current coordinates.
3232
3333
For the cursor to remain responsive you must keep a reference to it.

0 commit comments

Comments
 (0)
0