Avoid string translated as date when plot scatter


I have a problem where a string is translated into dates, without my intent. For example if I run on Python:

import plotly.express as px
fig = px.scatter(x=[β€˜00-01’, β€˜01-02’, β€˜02-03’], y=[0, 1, 4,])

The β€˜00-01’ is translated into β€˜Jan 2000’ on the x-axis when visualized. I just want it to show 00-01 on the x-axis. While when running with β€˜x=[β€˜12-13’, β€˜13-14’, β€˜14-15’]’ this is not a problem.

How can I avoid that it interpret it as dates?


Hi, you can force the axis type to be β€˜category’ as follows

import plotly.express as px
fig = px.scatter(x=['00-01', '01-02', '02-03'], y=[0, 1, 4,])

(plotly is interpreting strings formatted like dates as dates, but you can override this behaviour)

1 Like

Thank you Emmanuelle for your fast answer :slight_smile:

How to avoid that in the legend?

Does not work for plots that use facet_col or facet_row. It is only applied to the last facet.

Thats becasue you have more than just one xaxis. You’ll have to use fig.for_each_xaxis()