Skip to content

X-axis in plot not following dataframe order #2122

Closed
@robroc

Description

@robroc

I grouped a dataframe's datatime column to weekly periods, and when plotted, the x-axis doesn't follow chronologically, even if the dataframe in sorted properly:

plotly

Here's the relevant code in case it's helpful:

to_plot = (df.groupby(['colA', df.ad_delivery_start_time.dt.to_period('W').astype(str)])
  .size()
  .reset_index(name='ads')
  .sort_values('ad_delivery_start_time')
)

px.line(to_plot, x='ad_delivery_start_time', y='ads', color = 'colA', height=600)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions