Skip to content
Advertisement

Plotly: using fig.update_xaxes showes wrong month

I am looking for a solution to show the x_axis correct. the date 2021-01-31 is displayed as “Feb 2021”. i would like to show it as “Jan 2021”. thanks for help!

JavaScript

Advertisement

Answer

You can force the ticks to start at 2021-01-31 by setting the starting tick to the starting date of your data sdate.

JavaScript

enter image description here

I should point out that this plot has the potential to be misleading as I believe most people would interpret each tickmark as starting at the beginning of the month (e.g. most people would think that the data starts on 2021-01-01) if you don’t specify the day in your tickformat, but that is up to you depending on what you want to show on your chart.

If you instead you change the tickformat by rewriting the line fig.update_xaxes(dtick="M1", tickformat="%b %d %Y") then you get the following plot:

enter image description here

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