plotly / plotly/plotly.py

null values reset stacking in express barchart

Open
#5,324 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

It seems like null values in the middle of a series reset the stacking so that the next value starts at zero. I tried it upstream in a JS codepen and it is handled okay there, so I believe it is an issue with the python API or possibly with plotly.express.

Reprex modified from https://plotly.com/python/bar-charts/#bar-charts-with-text

import plotly.express as px

wide_df = px.data.medals_wide()

# set null value in middle 'silver' series
wide_df.iloc[0,2] = None

fig = px.bar(
  wide_df, 
  x="nation", 
  y=["gold", "silver", "bronze"], 
  title="Nulls Reset Stacking", 
  text_auto=True)

fig.show()

Output:

Image

Based on input data:

Image

Note that South Korea should be stacked to a total of 35 and not 24.

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 with the plotly.express.bar call in the supplied reproducer and compare its null-handling with the upstream JavaScript behavior referenced in the issue. Recreate the example using the medals_wide data and verify that South Korea's following bar remains stacked to a total of 35 rather than restarting at zero.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.