I know that a solution to what I am asking is this one.
The situation is the following:
I have a matrix whose first row is a list of identification numbers. Each column of the matrix (there are M columns) is the identification number of the column plus a vector of N components. I take each of these vectors and perform clustering. Once I get the clusters in the N-dimensional space I reduce the space with PCA to get a 2-dim space in which I can plot the vectors.
There are K clusters, each of them containing some of the M vectors, that after PCA are 2-dim vectors. I save these M 2-dim vectors in groups corresponding to the K clusters, then I plot each group with a different colour to distinguish them.
I understand that if I plot a scatter plot with data X=[x1,...,xn]
, Y=[y1,...,yn]
and I write picker=true
, then when I click on the jth point in the plot, there will be returned an index j. Of course when I plot K times (to plot the K clusters), there will be K points that have index = 0. This is problematic for the following reason:
The identification numbers can be put into a list ids = thematrix[0, :]
(the first row). My idea is that when I click a point I want to get an index that correctly relates the point to the id. But since many points have index = 0,1,..., then I click many points and I get the same id.
Here's the code I am using to plot the clusters and to get the index.
for i in xrange(len(useful_clusters)):
cluster = useful_clusters[i]
colour = colours[i]
ax.scatter(cluster[:, 0], cluster[:, 1], color=colour, marker='o', s=np.pi * 3 ** 2, alpha=0.95, lw=0, picker=True)
fig.canvas.mpl_connect('pick_event', onpick3)
How could I plot every single point in the order given by ids
so that when I click on any point I correctly get the id corresponding to that point?
I appreciate your help.