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!!

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.