🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Date as 'xaxis' not working (solved)

Hey guys,

I’ve been struggling for 3 hours on this issue without any sign of progress. I have a pandas dataframe with a ‘Date’ column. This column’s dtype is datetime64[ns].

Now I simply want to display a scatter/line chart with the date in the xaxis, and another data in the yaxis. So Basically I go:

'data': [go.Scatter(
                x=df.Date,
                y=df['CA HT'],
                text=df.Date,
            )],

But nothing ever appears on the graph. If I replace the xaxis with a completely different integer-type data, it works. But as soon as I want to display by dates, nothing happens.

I’ve read some other topics where it read “elements must be datetime or string with the ‘YYYY-MM-DD’ format”, so I tried:

'data': [go.Scatter(
                x=df.Date.dt.strftime('YYYY-MM-DD),
                y=df['CA HT'],
                text=df.Date,
            )],

But it doesnt’ work.
Any help would be greatly appreciated

I found the solution. I did some more research and stumbled upon this topic (Ploting time series data) where an working example was provided.

I basically progressively replaced my code to figure out which part was wrong. In the ‘layout’ part (within ‘figure’), I had specified:

xaxis={‘type’: ‘linear’}

Removing this line fixed my issue.

Hopefully this post will be helpful to others.

1 Like

Very helpful, thanks a lot!! Man, you would think it would just work… Like you, I’ve been at this for hours!