Home > Blockchain >  Add x-axis to matplotlib with multiple y-axis line chart
Add x-axis to matplotlib with multiple y-axis line chart

Time:11-17

How do I add the x-axis(Month) to a simple Matplotlib

My Dataset:

  Month Views   CMA30
0   11  24662   24662.000000
1   11  2420    13541.000000
2   11  11318   12800.000000
3   11  8529    11732.250000
4   10  78861   25158.000000
5   10  1281    21178.500000
6   10  22701   21396.000000
7   10  17088   20857.500000

This is my code:

df[['Views', 'CMA30']].plot(label='Views', figsize=(5, 5))

This is giving me Views and CMA30 on the y-axis. How do I add Month(1-12) on the x-axis?

CodePudding user response:

If you average the values per month, then try groupby/mean:

df.groupby('Month')[['Views','CMA30']].mean().plot(label='Views', figsize=(5, 5))
  • Related