In the simplest example of using mpl_point_clicker, points are obtained by clicking on an image. However, the resulting array when printed is empty, because the code is executed before I can click on the image.
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('QT5Agg')
import numpy as np
from mpl_point_clicker import clicker # https://mpl-point-clicker.readthedocs.io/en/latest/
empty_plot = np.zeros((10,10))
fig, ax = plt.subplots()
plot1 = ax.imshow(empty_plot)
klicker = clicker(ax,['point'],markers=['x'])
plt.show()
print(klicker.get_positions())
The above code results in the following:
{'point': array([], dtype=float64)}
This seems to be a common issue for Python: https://stackoverflow.com/questions/17149646/matplotlib-force-plot-display-and-then-return-to-main-code, https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue
Unfortunately none of the proposed solutions in those links work for me. I’m working with several hundred images, looking for specific features in them. I’m trying to get XY positions of the features, add that information to a dataframe, and then plot the next set of images to repeat the process.
Since I’d imagine that anybody using or developing mpl_point_clicker might also want to use point position information in their code, I’m hoping there might be a known way to work around this problem.
Thanks!