Edit: ax.scatter(event.xdata, event.ydata)
works fine, IDK how I went past this. However, pressing the button is still paint dots and I'm wondering if filtering coordinates is good practice to solve this.
Here is my minimal code to plot some points on axis. Unfortunately, with the button code plt.scatter()
stops working properly (dots start to appear on top of the button).Any advice for me?
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
def onclick(event):
plt.scatter(event.xdata, event.ydata)
fig.canvas.draw()
cid = fig.canvas.mpl_connect('button_press_event', onclick)
def do(event):
print(1)
bprev = Button(plt.axes([0.7, 0.05, 0.1, 0.075]), 'Previous')
bprev.on_clicked(do)
plt.show()