0

I'm trying to plot my table into a graph which has dates, from what I've learnt I've changed the date column into recognisable date by

pd.to_datetime(df["Date"], format="%Y%m%d")

My data looks something like this:

Date DailyPositive
1 20200101 1
2 20200102 2
3 20200103 4

When I try plotting it, my graphs came out like this, I'm assuming it somehow plotted against the index instead?

enter image description here

How do I plot the date at X axis, and the cases at Y-axis? Also since my date runs across two years, is there a way for to make the X-axis date go in like maybe few months apart?

I've searched around and saw way too many different solutions for me to understand :(

Thank you!!

mnist
  • 6,571
  • 1
  • 18
  • 41
Moon Chan
  • 13
  • 3

1 Answers1

0

For a regular plot, you just can use line

DF2.plot.line(x="Date", y="DailyPositive")

enter image description here

For adding some space, you can set the xlim kind of dynamically like this:

DF2.plot.line(x="Date", y="DailyPositive", xlim=[min(DF2["Date"]) + pd.DateOffset(-1), max(DF2["Date"]) + pd.DateOffset(1)])

enter image description here

mnist
  • 6,571
  • 1
  • 18
  • 41