I have a function call draw. I have 2 lists, one with x coordinates an second with y coordinates. I'm making a plot, and I want to write in the plot the x,y coordinates. I see that annotate may be the answer but it can't get a list. I'm trying to do this:
def draw(LuxCoordinates, finalPix, verName, GraphNum):
xy = (LuxCoordinates,finalPix)
plt.axes([0.1, 0.1, 0.6, 0.8]);
plt.xlim(0,3100,);
plt.ylim(0,100,100);
plt.xticks(arange(0,3500,350)) #spaces of x axis
plt.yticks(arange(0,100,10)) #spaces of y axis
if GraphNum == 1:
plt.plot(LuxCoordinates, finalPix, 'r', label=verName);
if GraphNum == 2:
plt.plot(LuxCoordinates, finalPix, 'g', label=verName);
if GraphNum == 3:
plt.plot(LuxCoordinates, finalPix, 'b', label=verName);
legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.scatter(LuxCoordinates, finalPix, linewidths=1)
**for i, txt in enumerate(xy):
plt.annotate(txt, (LuxCoordinates[i],finalPix[i]))**
plt.grid(axis)
plt.xlabel('Ambient', color='r');
plt.ylabel('Depth Grows', color='r'); # grayscale color
plt.title(PngName, color='b');
savefig(PngName+'_'+date+'_'+currentime+'.png')
But I'm getting this:
And in zoom in: You can see it write something, but it's all the list on the first point, I want each x,y will be written near to the point separately, so the first point in the blue graph will be 0,96.6, and in the green it will be 0, 93.54 (you can see the 2 lists)
Can someone please help me with that? Thanks!
Your
xy
has two lists in it to enumerate, not one for each point as you're expecting. Try replacingxy = (LuxCoordinates,finalPix)
withxy = zip(LuxCoordinates,finalPix)
. Alternatively, if you're usingxy
in its current form elsewhere you could transpose the array in your enumerate call: