bokeh: [BUG] vbar_stack with positive and negative values does not plot correctly
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)

Expected Output:

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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (12 by maintainers)
Commits related to this issue
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to gurneyalex/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to gurneyalex/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to gurneyalex/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to hmagninfeysot/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
- [IMP] project_forecast_line_bokeh_chart Enhance the display in the bokeh chart to better display negative consolidated capacity. Without the fix, the stacked vbar would display the negative capacity... — committed to sunflowerit/project by gurneyalex 2 years ago
@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
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…
@bryevdv I have read through this discussion in the meantime and I cannot fully follow the objections. From a library that can plot stacked bar charts one would expect that it can handle negative numbers correctly… So to be honest, I do not see / understand the use case for the current behavior. There may be certain implementation reasons at the current state of development, but from a user perspective - I am sorry - it does not make sense (at least to me and to others in this thread at least)
@nabilahmed739 Nothing about my previous analysis above has changed, I am -1 on processing the data at this level. From my perspective, this is a relatively marginal use-use, that can still be otherwise accomplished, that would be non-trivial to implement and maintain, and possibly lead to increased support burden due to confused/overly complicated semantics. As I mentioned it probably makes more sense to ask about something like this on a higher level tool like Holoviews, that is built on top of Bokeh.
I have the same expectation as @JING1201 here:
@bryevdv It would be great if the negative values stacked together on the other side of 0. In case data manipulation is required, can we have a flag based on which bokeh can render differently for this scenario or manipulate the data(if need be) and the users use the feature with caution? Is there a possibility of opening up this issue for the new version of Bokeh?
@bryevdv Thanks for the explanation! However, could we reopen the issue as a feature perhaps? I think having a feature that automatically splits the data for the user for vbar_stack and other methods that uses _double_stack would be beneficial since having data with mixed signs is not uncommon, and overlapping is not the desired output in most cases. I have seen a lot of others asking about this online, and such feature has been added in plotly and holoviews.