In [2]:
from bokeh.charts import Bar, output_notebook, show
from bokeh.charts.attributes import cat, color
from bokeh.charts.operations import blend
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data


output_notebook()

# 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)


Loading BokehJS ...
/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/ipykernel/__main__.py:15: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)

In [3]:
bar_from_gallery = 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",
          tooltips=[('medal', '@medal'), ('country', '@abbr')])


show(bar_from_gallery)


Out[3]:

<Bokeh Notebook handle for In[3]>


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


show(bar_from_issue)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-0e16afd5df97> in <module>()
      2           values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
      3           label=cat(columns='abbr', sort=False),
----> 4           stack=cat(columns='medal', cats=('bronze', 'silver'), sort=False),
      5           color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
      6                       sort=False),

/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/bokeh/charts/attributes.py in cat(columns, cats, sort, ascending, **kwargs)
    399     kwargs['ascending'] = ascending
    400 
--> 401     return CatAttr(**kwargs)

/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/bokeh/charts/attributes.py in __init__(self, **kwargs)
    317 
    318     def __init__(self, **kwargs):
--> 319         super(CatAttr, self).__init__(**kwargs)
    320 
    321     def _setup_iterable(self):

/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/bokeh/charts/attributes.py in __init__(self, columns, df, iterable, default, items, **properties)
    108             properties['items'] = items
    109 
--> 110         super(AttrSpec, self).__init__(**properties)
    111 
    112         if self.default is None and self.iterable is not None:

/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/bokeh/core/properties.py in __init__(self, **properties)
    699 
    700         for name, value in properties.items():
--> 701             setattr(self, name, value)
    702 
    703     def __setattr__(self, name, value):

/Users/caged/miniconda3/envs/bokeh_miscellany/lib/python3.5/site-packages/bokeh/core/properties.py in __setattr__(self, name, value)
    720 
    721             raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
--> 722                 (name, self.__class__.__name__, text, nice_join(matches)))
    723 
    724     def set_from_json(self, name, json, models=None):

AttributeError: unexpected attribute 'cats' to CatAttr, possible attributes are ascending, attr_map, attrname, bins, columns, data, default, items, iterable or sort

In [ ]: