Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Avoid string translated as date when plot scatter

Hi,

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,])
fig.show()

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?

Regards
Eddie

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,])
fig.update_layout(xaxis_type='category')
fig.show()

(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: