1

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?

2
  • 1
    You have four Views and CMA30 per month. How do you want to plot those? Commented Nov 16, 2022 at 16:46
  • @BigBen, I just average them out Commented Nov 16, 2022 at 17:08

1 Answer 1

2

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

df.groupby('Month')[['Views','CMA30']].mean().plot(label='Views', figsize=(5, 5))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.