By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,591 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,591 IT Pros & Developers. It's quick & easy.

finding the position of a point in a matplotlib plot

P: 1
Hi all,

I am plotting a dot plot of x vs y like the example below:
Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. a = np.random.random(750)
  5. b = np.random.random(750)
  6.  
  7. fig = plt.figure()
  8. ax = fig.add_subplot(111)
  9. ax.plot(a, b, 'ro')
  10. plt.show()
  11.  
I have 750 points - and would like to be able to get information about the origin of the point via a mouseover. I know I could plot labels - but with so many points it's going to be messy. I've tried to use the mpldatacursor as a solution - and this works well if you want to get the x,y co-ords of the point, but it doesn't give me a value I can use to easily pinpoint the values plotted (for example the position in the numpy array). Is it possible to get the position in the array (other than by plotting labels?) via a mouseover?
May 4 '13 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 626
You have to know where the points are plotted, something like a dictionary of x,y locations for each point, which can then be compared to the location of the mouse. If the points are not discontinuous, i.e. in some order like smallest to largest then there may be a way to calculate mouse distance from the zero point and which point is plotted at that location.
May 4 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.