KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using pandas and matplotlib to visualize this dataframe HDD EnergyPerSquareMeter Year 0 3333.6 23.11 1997 1 3349.6 24.30 1998 2 3319.5 24.78 1999 3 3059.1 22.01 2000 4 3287.5 24.17 2001 5 3054.9 20.01 2002 6 3330.0 21.25 2003 7 3307.3 19.22 2004 8 3401.4 18.31 2005 9 3261.6 20.40 2006 10 3212.8 15.34 2008 11 3231.2 15.95 2009 12 3570.1 15.79 2010 13 2995.3 13.88 2011 And I would like to plot EnergyPerSquareMeter as scatterplot (with the x-axis=HDD) and annotate the points with the year. I did this: ax =EnergyvsHDD.plot(x='HDD', y='EnergyPerSquareMeter', marker="o" , linestyle='None', figsize=(12,8)) for i, txt in enumerate(EnergyvsHDD['Year']): ax.annotate(txt, (x[i],y[i]), size=10, xytext=(0,0), ha='right', textcoords='offset points') The outcome is: The annotated text of the years doesn´t appear near the points. What am I doing wrong? UPDATED Using this code: def label_point_orig(x, y, val, ax): a = pd.concat({'x': x, 'y': y, 'val': val}, axis=1) print a for i, point in a.iterrows(): ax.text(point['x'], point['y'], str(point['val'])) And then: ax = EnergyvsHDD.set_index('HDD')['EnergyPerSquareMeter'].plot(style='o') label_point_orig(EnergyvsHDD.HDD, EnergyvsHDD.EnergyPerSquareMeter, EnergyvsHDD.Year, ax) draw() The points don't appear in the proper place: Although using this code it works: plt.scatter(list(EnergyvsHDD.HDD), list(EnergyvsHDD.EnergyPerSquareMeter)) label_point_orig(EnergyvsHDD.HDD, EnergyvsHDD.EnergyPerSquareMeter, EnergyvsHDD.Year, plt) draw() <img src=
Tags (comma-separated)
Save Edits
Cancel