I want to create a stacked bar chart showing contributions to the total from different categories. I can do this by splitting the data into positive and negative data, and then plotting separate stacked bars from both. How can I then clean up the hover tools, so instead of that showing two sets, one for the positive CDS and one for negative CDS, there would just be one? So, instead of 2015 showing
Apples: 1
Pears:3
Nectarines: 0
And
Apples: 0
Pears:0
Nectarines: -4
It would just show:
Apples: 1
Pears:3
Nectarines: -4
d = {'Apples' : [1,-5,8],
'Pears' : [3,-9,4],
'Nectarines' : [-4, 7, -6]}
df = pd.DataFrame(d,index=['2015', '2016', '2017'])
df.rename_axis('Date', axis=0, inplace=True)
df = df.apply(pd.to_numeric)
pos = df.mask(df <0)
neg = df.mask(df >0)
p = figure()
cats = ['Apples','Pears','Nectarines' ]
labels = ['Apples','Pears','Nectarines']
colors = ['blue', 'steelblue', 'lightblue',]
p.vbar_stack(stackers=cats, x="Date", width=0.3, source=ColumnDataSource(m), color = colors, legend_label=labels)
p.vbar_stack(stackers=cats, x="Date", width=0.3, source=ColumnDataSource(x), color = colors, legend_label=labels)
hover = HoverTool()
hover.tooltips = [('Date', '@Date{%F}'),
('Apples', '@{Apples}{0,0.0}'),
('Pears', '@{Pears}{0,0.0}'),
('Nectarines', '@{Nectarines}{0,0.0}')]
hover.formatters = {'@Date': 'datetime'}
p.add_tools(hover)
show(p)