Scatter chart: xasix category order fail to be unsorted

I have DataFrame with a specially sorted index as below (neither ascending nor descending):

Index([40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
dtype=‘object’, name=‘Week’)

as the doc instructed, I wrote to make the xaxis category keep the order as the index originally has:
image

but it failed that the fig still with an ascending order:

Hi @michaelyang,

try converting your index into string:

import random
import plotly.graph_objects as go

x = [*range(50)]
random.shuffle(x)
x = [str(item) for item in x]

y = [*range(50)]

fig = go.Figure(
    go.Scatter(
        x=x,
        y=y,
        mode='lines+markers'
    )
)
fig.show()

Yup, it works perfectly on my side also. Thanks Very Much!!

1 Like