0

Plotting scatters I am using below:

import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

dates = ['2015-12-20','2015-09-12','2015-08-12','2015-06-12']  
PM_25 = [68, 66, 55, 46]

dates = [pd.to_datetime(d) for d in dates]

plt.scatter(dates, PM_25, s =50, c = 'red')
plt.show()

For each of the scatters, I want to add data label 'date' to it. So I made these changes:

fig, ax = plt.subplots()
ax.scatter(dates, PM_25)
for i, txt in enumerate(dates):
    ax.annotate(txt, i)

enter image description here

It doesn't work.

What's the right way to label them? Thank you.

Mark K
  • 8,767
  • 14
  • 58
  • 118

1 Answers1

1

You need both x and y when you annotate.

for i, txt in enumerate(dates):
    ax.annotate(txt, (dates[i],PM_25[i]))
Henry Yik
  • 22,275
  • 4
  • 18
  • 40