plotly / plotly/plotly.py

wrong location of xticks in plotly express

Open
#3,798 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

plotly version: 5.9.0
Python: 3.9.13 on Apple silicon running OSX 12.2

Reproducible example:

import pandas as pd
import plotly.express as px
df = pd.DataFrame({
    'date': pd.date_range(start='2022-01-01', end='2022-06-30', freq='1D'),
    'y': 1,
})
df['weekday'] = df['date'].dt.weekday.astype('str')
df = df.set_index('date')
df = df.groupby('weekday').resample('M').agg({'y': 'sum'}).reset_index()
px.bar(df, x=df['date'], y=df['y'], color=df['weekday'])

This leads to:
newplot

One can see that the last bar is shown above July whereas it actually corresponds to June. All xticks should be moved one month back on this graph.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Python example through the plotly.express px.bar entry point and inspect how the resampled date values are used for x-axis ticks. The fix is complete when the final bar is labeled under June rather than July and the other month labels remain correctly aligned.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.