In R, there is a function locator
which is like Matlab's ginput
where you can click on the figure with a mouse and select any x,y coordinate. In addition, there is a function called identify(x,y)
where if you give it a set of points x,y that you have plotted and then click on the figure, it will return the index of the x,y point which lies nearest (within an adjustable tolerance) to the location you have selected (or multiple indices, if multiple points are selected). Is there such a functionality in Matplotlib?
But did you know that it is also possible to create interactive plots with matplotlib directly, provided you are using an interactive backend? This article will look at two such backends and how they render interactivity within the notebooks, using only matplotlib.
Asynchronous Plotting in Matplotlib: rather than call savefig directly, add plots to an asynchronous queue to avoid holding up the main program. Makes use of multiple processes to speed up the writing out.
Interactively selecting data points with the lasso tool. This examples plots a scatter plot. You can then select a few points by drawing a lasso loop around the points on the graph. To draw, just click on the graph, hold, and drag it around the points you need to select.
Matplotlib plots do not display in Pycharm. The % notation is for using the magic functions available in python, and %matplotlib inline, represents the magic function %matplotlib, which specifies the backend for matplotlib, and with the argument inline you can display the graph and make the plot interactive.
You may want to use a pick event :
fig = figure() ax1 = fig.add_subplot(111) ax1.set_title('custom picker for line data') line, = ax1.plot(rand(100), rand(100), 'o', picker=line_picker) fig.canvas.mpl_connect('pick_event', onpick2)
Tolerance set by picker parameter there:
line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance
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