0

I'm plotting a handful of coordinates using two lists, x and y. I have a third list which is a list of labels. I want to apply the corresponding label to every (xᵢ,yᵢ) pair.

I'm plotting the coordinates using this command:

self.map.plot(x, y, 'bo', markersize=10, picker=5)

I know that you can use the label="my label here" argument, but I'm not sure how to do it for each coordinate.

Example Data

x = [10,20,24,90]
y = [04,20,40,100]
labels = ["dog", "fish", "cat", "mouse"]
  • (10,4) would have the label "dog".
  • (20,20) would have the label "fish".
  • (24,40) would have the label "cat".
  • (90,100) would have the label "mouse".
Veedrac
  • 58,273
  • 15
  • 112
  • 169
Jaron Bradley
  • 1,079
  • 3
  • 16
  • 24
  • you may like this http://stackoverflow.com/questions/5147112/matplotlib-how-to-put-individual-tags-for-a-scatter-plot – joaquin Sep 27 '14 at 09:43
  • @joaquin: This question is interesting, but it is about annotations, which typically include an arrow from the text to the point. I gather that the question is about simple labels. – Eric O. Lebigot Sep 27 '14 at 09:47
  • hi @EOL, more conventional then, http://stackoverflow.com/questions/22272081/label-python-data-points-on-plot, just add labels to zip(x,y,labels) instead using coordinates – joaquin Sep 27 '14 at 09:52
  • Good digging. :) A simple `pyplot.text()` works too. However, Jaron just left a comment in my deleted answer, indicating that he wants the label to instead appear when *clicking* on a point. – Eric O. Lebigot Sep 27 '14 at 09:57
  • I can fix the question up. I have my onpick() callback set up which uses event.artist.get_label() to return the label of the dot clicked on... i just don't know how to set the labels for each dot. I know it's probably really basic. :( – Jaron Bradley Sep 27 '14 at 09:59
  • http://wiki.scipy.org/Cookbook/Matplotlib/Interactive_Plotting – joaquin Sep 27 '14 at 10:02

1 Answers1

0

Alright. I was making this far harder than it needed to be. The answer is to use zip() (see comments. Thanks @joaquin )

    for x_entry, y_entry, label in zip(x,y,labels):
        print label
        self.map.plot(x_entry, y_entry, 'bo', markersize=10, picker=5, label=label)
Jaron Bradley
  • 1,079
  • 3
  • 16
  • 24