SAM H
SAM H

Reputation: 11

Python: Line Plot - Formatting Dates on X axis?

I am trying to plot the dates from an excel file for a line chart. It is in Column A labeled "Date" and is in the format 3/1/2019. The type is "short date" on excel. I've managed to pull in the excel data and the columns I needed into a data frame. When i try to plot using:

plt.plot(GQ1_Date, GQ1_WICreated)
plt.plot(GQ1_Date, GQ1_Backlog)
plt.show()

GQ1_Date.head() outputs:  

       Date
0 2019-03-01
1 2019-03-02
2 2019-03-03
3 2019-03-04
4 2019-03-05

the x axis reads 2019-03, 2019-05, etc. How do I get it to display the full date with the day and make the ticks display every single date insetad of every 2 months?

Upvotes: 1

Views: 26

Answers (1)

dzakyputra
dzakyputra

Reputation: 682

I think that's because your Series is in datetime data type.

Try this.

plt.plot(GQ1_Date['Date'].astype(str), GQ1_WICreated)
plt.plot(GQ1_Date['Date'].astype(str), GQ1_Backlog)
plt.xticks(rotation=90)
plt.show()

Upvotes: 1

Related Questions