Stacked bar chart rendering bug in the presence of negative values
See original GitHub issueHi,
Really enjoying Altair but I’ve run into a bug when attempt to display stacked bars, some of which contain negative values.
Here is a minimal test case that demonstrates the problem.
import pandas as pd
from altair import Chart
data = pd.DataFrame({'amount': [-2000, 3000, 2000, 4000, 3000, 5000, 1000, 2000],
'quarter': ['Q1', 'Q1', 'Q2', 'Q2', 'Q3', 'Q3', 'Q1', 'Q1'],
'type': ['N', 'C', 'N', 'C', 'N', 'C', 'N', 'C'],
'year': [2016, 2016, 2016, 2016, 2016, 2016, 2017, 2017]})
Chart(data).mark_bar().encode(
color='type:N',
column='quarter:O',
x='year:N',
y='sum(amount):Q',
)
Which produces this view:
If you remove the sum()
aggregation from the y
axis, the negative values are displayed but you lose the stacking.
Chart(data).mark_bar().encode(
color='type:N',
column='quarter:O',
x='year:N',
y='amount:Q',
)
Which looks like this:
Anyone else run into this issue?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Negative Values Don't Appear in Stacked Bar Charts
Hello, We noticed today (not sure when it started though) that negative values in our 100% stacked bar charts no longer appear when...
Read more >Kibana 8.2.3 "Donut chart can't render with negative values"
The error message is reporting the fact that some slices of the donut chart have a negative size, which don't make sense. Do...
Read more >Negative values with stacked bar chart don't work well
We have started creating stacked bar charts, and we find that the StackedBarSeries really doesn't handle negative values reasonably.
Read more >Help - iTOL
In multi value bar charts, each tree node is associated to multiple numeric values, which are displayed as a stacked or aligned bar...
Read more >A Complete Guide to Stacked Bar Charts | Tutorial by Chartio
Each bar in a standard bar chart is divided into a number of sub-bars stacked end to end, each one corresponding to a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The latest version of Vega (3.0.0-beta.26) has an updated stack transform that can properly handle negative numbers. As a result, Vega-Lite 2.0 will ultimately “do the right thing” here.
Thanks @jheer and @kanitw for the clarification. Closing as question/vega-lite