python - Can matplotlib pick_event return array indeces rather than values or pixels? -


I am trying to write a plot picker for a plot in matplotlib. To tell me this, I want to, where I clicked towards the conspiracy of Jammu and Kashmir. It seems that the only option is for the event. Mouseevent.xdata, which is in the context of plotted coordinate values ​​or event. Mouseevent.x, which is in reference to pixels (which I can see is not "pixels" similar to grid box, which I see).

Did I misunderstood what xdata / x is

thanks nil

edit: the image that is being clicked on the plot of 2D array For example, with pcolormesh

You can:

    < Li> Make your artist first (array in the example given below). / Li>
  • On click action, check that the artist will click on the artist
  • Use the event.ind [0] property to get the index.

The following example document is:

x = linspace (0,1,100) as y = cos (x * 8 *) as

numpy import from linspace, cos, pi as import matplotlib.pyplot plt

 pi) # your array figs = plt.figure () ax = fig.add_subplot (111) line, = Ax.plot (x, y, 'b', picker = 10) def onpick (event): if event.artist! = Line: #Check that you click on the object that you wanted to return true if the true (if event.ind): # check index is a valid return true ind = event.ind [0] ax.plot (x [Ind], y [ind], 'ro') fig.canvas.draw () back to the right fig.canvas.mpl_connect ('pick_event', onpick) fig.show ()  

Enter image details here

EDIT: OK after that you first have your grid points You can plot a line on it, then you can attract your pcolormesh object upwards, and the line Can Ipa. Here is the code

  x = linspace (0, 9, 10) + 5 y = linspace (0, 9, 10) + 5 # Your array x, y = meshgrid (x, y) X = x.flatten () y = y.flatten () fig = plt.figure () ax = fig.add_subplot (111) row, = ax.plot (x, y, 'b', picker = 10) line Set_visible (false) ax.pcolormesh (np.random.randn (10,10)) def onpick (event): If event.artist! = Line: #check The True if not (Event.ind) if you click on the object you want to return to: # Check Index is a valid return True ind = event.ind [0] ax.plot (x [ind], Y [ind], ro ') fig.canvas.draw () return true fig .canvas.mpl_connect (' pick_event ', onypic) fig.show ()  


Comments

Popular posts from this blog

Removing From ArrayList, In Loop Based On It's Size, But Breaking After Remove Still Gives OutOfBounds -

c# - Reactive Extensions ControlScheduler -

java - Add color code support to a Bukkit plugin -