from bokeh.charts import Bar, output_file, show
from bokeh.charts.operations import blend
from bokeh.charts.attributes import cat, color
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

from bokeh.models.tools import HoverTool

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort("total", ascending=False)

bar = Bar(df,
          values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals")

bar.add_tools(HoverTool(tooltips=[('medal', '@medal'), ('country', '@abbr')]))

output_file("stacked_bar.html")
show(bar)

from bokeh.charts import Bar, output_file, show
from bokeh.charts.operations import blend
from bokeh.charts.attributes import cat, color
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort("total", ascending=False)

bar = Bar(df,
          values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals",
          hover=[('medal', '@medal'), ('country', '@abbr')])


output_file("stacked_bar.html")
show(bar)

Update stacked bar example to use the hover kwarg.
Update stacked bar example to use the hover kwarg.

  from bokeh.charts import Bar, output_file, show
  from bokeh.charts.operations import blend
  from bokeh.charts.attributes import cat, color
  from bokeh.charts.utils import df_from_json
  from bokeh.sampledata.olympics2014 import data
- 
- from bokeh.models.tools import HoverTool
  
  # utilize utility to make it easy to get json/dict data converted to a dataframe
  df = df_from_json(data)
  
  # filter by countries with at least one medal and sort by total medals
  df = df[df['total'] > 0]
  df = df.sort("total", ascending=False)
  
  bar = Bar(df,
            values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
            label=cat(columns='abbr', sort=False),
            stack=cat(columns='medal', sort=False),
            color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                        sort=False),
            legend='top_right',
-           title="Medals per Country, Sorted by Total Medals")
+           title="Medals per Country, Sorted by Total Medals",
+           hover=[('medal', '@medal'), ('country', '@abbr')])
  
- bar.add_tools(HoverTool(tooltips=[('medal', '@medal'), ('country', '@abbr')]))
  
  output_file("stacked_bar.html")
  show(bar)
  
Update stacked bar example to use the hover kwarg.
## Code Before:
from bokeh.charts import Bar, output_file, show
from bokeh.charts.operations import blend
from bokeh.charts.attributes import cat, color
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

from bokeh.models.tools import HoverTool

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort("total", ascending=False)

bar = Bar(df,
          values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals")

bar.add_tools(HoverTool(tooltips=[('medal', '@medal'), ('country', '@abbr')]))

output_file("stacked_bar.html")
show(bar)

## Instruction:
Update stacked bar example to use the hover kwarg.
## Code After:
from bokeh.charts import Bar, output_file, show
from bokeh.charts.operations import blend
from bokeh.charts.attributes import cat, color
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort("total", ascending=False)

bar = Bar(df,
          values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals",
          hover=[('medal', '@medal'), ('country', '@abbr')])


output_file("stacked_bar.html")
show(bar)
