0

I want to plot the mean based on month and years.

My data have two columns (count, mean) and the date as index.

As shown here is a plot similar to my plot where x is years and y is mean

enter image description here

Here is my code

    import matplotlib.pyplot as plt
    diet = df[['mean']]
    diet.plot(figsize=(20,10), linewidth=5, fontsize=20 ,marker='<')
    plt.xlabel('Year', fontsize=20);
    plt.xlabel('Month/Year')
    plt.ylabel('mean')

Is there any way to add the count column on the all point line like this to know the count number in each month. enter image description here

Fatima
  • 497
  • 5
  • 21
  • Does this answer your question? [Annotate Time Series plot in Matplotlib](https://stackoverflow.com/questions/11067368/annotate-time-series-plot-in-matplotlib) – Diziet Asahi Feb 13 '20 at 10:34
  • @DizietAsahi not much, because i want to add column not one word – Fatima Feb 13 '20 at 10:37
  • Well, you have to run a loop to add one word for each row of your df. Sorry. – JohanC Feb 13 '20 at 11:07

1 Answers1

1
idx = pd.date_range(start='1901-01-01', end='1903-12-31', freq='1M')
df = pd.DataFrame({"mean": np.random.random(size=(idx.size,)), "count": np.random.randint(0,10, size=(idx.size,))}, index=idx)

plt.figure()
ax = df['mean'].plot(figsize=(8,4))
for d,row in df.iterrows():
    ax.annotate('{:.0f}'.format(row['count']), xy=(d,row['mean']), ha='center')

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75