Skip to content
Advertisement

Matplot lib generates Date in X-axis from Jan 1970

I have date index available in the following format:

JavaScript

But the following code generates wrong graph:

JavaScript

enter image description here

Advertisement

Answer

Your dataframe index is likely in the wrong format: str. You can check this with df.info(), if you have something like:

JavaScript

If that’s the case, you need to convert index type from str to datetime with:

JavaScript

Code example:

JavaScript

Without to_datetime conversion:

enter image description here

With to_datetime conversion:

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement