I'm currently using matplotlib and I need to store coordinates of two left clicks on a graph. (I'm calculating an integral between the two clicked points) Somehow, after hours and hours of trying, I haven't managed to save the two clicks. Does anybody here know how to do that?
Asked
Active
Viewed 174 times
-3
-
This question needs a [SSCCE](http://sscce.org/). Please see [How to ask a good question](https://stackoverflow.com/help/how-to-ask). Always provide a complete [mre] with **code, data, errors, current output, and expected output**, as **[formatted text](https://stackoverflow.com/help/formatting)**. If relevant, only plot images are okay. If you don't include an mre, it is likely the question will be downvoted, closed, and deleted. – Trenton McKinney Dec 07 '21 at 18:13
1 Answers
0
Use the ginput()
function. Here's an example:
import numpy as np
import matplotlib.pyplot as plt
# generate some data to plot
x = np.linspace(0, 10)
y = np.sin(x)
plt.plot(x, y)
print('please click twice on the plot')
clicks = []
for i in range(2):
clicks.append(plt.ginput())
print('your clicks were at locations:')
print(clicks)

AbbeGijly
- 1,191
- 1
- 4
- 5