tags:

views:

51

answers:

1

If I feed several x/y sets to matplotlib.pyplot.plot, how does annotate decide how to correlate the xy value to one of the sets? Is there an assumption that all the sets are scaled the same way?

 plt.plot(clist, plist, 'g', clist, rlist, 'r', clist, flist, 'b')
 plt.annotate("%d chars F=%f" % (threshold_c, threshold_f), xy=(threshold_c, threshold_f),
             xytext=(-50, 30), textcoords='offset points',
             arrowprops=dict(arrowstyle="->"))

We seem to have a good answer, but someone asked for clarification.

Calling annotate with the default xy= has the effect of associating an annotation with a graphed x/y pair. When there's one X array and one Y array, it's obvious to me what that means.

With multiples, I didn't know if plot was going to automatically set up multiple sets of axes, one for each X/Y array -- and, if so, how annotate was going to work. The answer explains that one call to plot creates one set of axes that scales all the X/Y sets as best it can, and so annotate knows where to go.

+1  A: 

You should think of annotate as associated with the axes and not the data. Multiple data sets can be plotted on the same axes, as in your example, or you can have different axes in the same plot, but then when you use annotate, etc, you'd want to specify which axes you wanted to annotate.

tom10