Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib -- interactively select points or locations?

Tags:

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?

like image 784
hatmatrix Avatar asked Nov 01 '11 16:11

hatmatrix


People also ask

Can you make matplotlib interactive?

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.

Is matplotlib asynchronous?

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.

How do you select points on a scatter plot in Python?

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.

What is the difference between %Matplotlib inline and %Matplotlib notebook?

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.


1 Answers

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 
like image 116
cyborg Avatar answered Sep 19 '22 08:09

cyborg