finding the position of a point in a matplotlib plot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sarracenia
    New Member
    • May 2013
    • 1

    finding the position of a point in a matplotlib plot

    Hi all,

    I am plotting a dot plot of x vs y like the example below:
    Code:
    import numpy as np
    import matplotlib.pyplot as plt
    
    a = np.random.random(750)
    b = np.random.random(750)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(a, b, 'ro')
    plt.show()
    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?
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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.

    Comment

    Working...