How is it possible to plot a dot/circle at the point being clicked on in matplotlib(python 3)? Moreover i want to read the pixel value of each dot. I have tried plotting the circles but each time i read a different coordinate value, the previous circle is overwritten by the new circle. thank you
In Matplotlib, we can draw multiple graphs in a single plot in two ways. One is by using subplot() function and other by superimposition of second graph on the first i.e, all graphs will appear on the same plot.
You have to register an onclick
event with the figure. Below is an example that plots a dot where the user clicks:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
def onclick(event):
print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
(event.button, event.x, event.y, event.xdata, event.ydata))
plt.plot(event.xdata, event.ydata, ',')
fig.canvas.draw()
cid = fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With