question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stacked bar chart rendering bug in the presence of negative values

See original GitHub issue

Hi,

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:

altair_stacked_bar1

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:

altair_stacked_bar2

Anyone else run into this issue?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jheercommented, Mar 16, 2017

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.

0reactions
ellisonbgcommented, Apr 19, 2017

Thanks @jheer and @kanitw for the clarification. Closing as question/vega-lite

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found