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.

[BUG] vbar_stack with positive and negative values does not plot correctly

See original GitHub issue

Expected Behavior: When the source data contain a mixture of positive and negative values, the bars with negative values will stack downward below 0 without interfering the positive bars.

Observed Behavior: When the source data contain a mixture of positive and negative values, the bars with negative values stack downward from the top of the previous positive bar, making that bar not visible.

Note: This is similar to the issue raised in plotly , and this is resolved by having a ‘relative’ barmode.

Software versions: bokeh 1.2.0 Python 3.6.8

OS: Windows 10

Example:

from bokeh.plotting import figure, show, save
from bokeh.io import output_notebook
from bokeh.core.properties import value
from bokeh.layouts import *

y_s = ['y1', 'y2']
data = {'x_values': [1, 2, 3, 4, 5],
       'y1': [-2, 5, 1, -2, 3], 
       'y2': [1, -9, -5, 1, -2]}
p = figure(title="Demonstration")
p.vbar_stack(['y1', 'y2'], x='x_values', width = 0.5, color = ['blue','red'], source = data, legend=[value(y) for y in y_s])
p.legend.click_policy="hide"
show(p)

image

Expected Output:

image

Although using separate vbar glyphs can solve the issue in this example, it will not be much help when there are more stacked bars and the data gets more complicated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
bsteubingcommented, Sep 28, 2021

@bryevdv thanks for your explanations. I have no deeper insights into the technical challenges you describe and the priorities at bokeh, but I do fully understand that you have to prioritize, so of course have to accept your “no” here.

However, as a scientist with 10+ years plotting experience, I fail to understand the logic behind this behavior. Why would stacked bar charts not plot as described here on top under “expected behavior”? I am not aware of any other plotting platform that does not offer this… it is a standard plot. Look at how pandas plots stacked bar charts. And even mainstream software like Excel does it like this. But OK, now we are turning in circles.

I would not be surprised if there were not quite a few others who’d like to use bokeh for stacked bar charts, but then either go elsewhere or do these additional transformations. So anyone, please up-vote this if you feel like you are missing this as well in bokeh.

Should you decide to re-open this issue at some point, it seems that plotly has implemented the behavior we’d be expecting, see here for future inspiration: https://github.com/plotly/plotly.js/issues/475 https://codepen.io/etpinard/pen/mPGLrY

2reactions
bsteubingcommented, Sep 28, 2021

Hi @bryevdv, I have not followed the full discussion here, but I am quite surprised that bokeh does NOT support stacked bar charts with mixed negative/positive numbers out of the box. This was such a “given” for us that we did not consider this in our evaluation to use bokeh for the Activity Browser project. Our implementation is still Matplotlib based, which is a fantastic plotting library, but not as good on the interactive side as bokeh. So while we are not decided yet whether we can actually use bokeh, this here seems to be the workaround for now, i.e. to split any data into a negative and a positive side and then add both separately to the figure. This is not only unnecessarily complicated and error prone, but also comes with the downside for us that for making this interactive it gets more complicated as we have to work with two underlying dataframes (tables) instead of just one (like in all other plotting libraries that I am aware of). So we’d appreciate very much if bokeh could offer a solution for supporting stacked bar charts in general instead of the current implementation…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stacked area plot not showing negative values properly
Using a stacked area plot with negative data doesn't make a lot of sense. How can you draw something with negative area? Do...
Read more >
negative values not stacking correctly on positive bars in a ...
In these cases the stacked negative bar is not stack at the bottom i.e. from the zero y value downwards but instead appears...
Read more >
Is the range of this plot correct using *ScalingFunctions -> "Log"
If I correctly understand it, you want to build a log-plot of a fuction taking negative values. In this case the ScalingFunctions ->...
Read more >
How to separate colors for positive and negative bars in ...
In this tutorial, I will introduce you an easy way for giving different colors to the positive and negative bars in column or...
Read more >
Plotting negative x values in App Designer - MATLAB Answers
I've tried reading the forums and I believe it is because there is "no non-positive indexing" in MatLab.... but I am rather stuck...
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