from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
from math import pi
import pandas as pd
from bokeh.palettes import Category20c
from bokeh.transform import cumsum
x = { 'United States': 157, 'United Kingdom': 93, 'Japan': 89, 'China': 63,
'Germany': 44, 'India': 42, 'Italy': 40, 'Australia': 35, 'Brazil': 32,
'France': 31, 'Taiwan': 31, 'Spain': 29 }
data = pd.Series(x).reset_index(name='value')
data = data.rename(columns={'index':'country'})
data['color'] = Category20c[len(x)]
# represent each value as an angle = value / total * 2pi
data['angle'] = data['value']/data['value'].sum() * 2*pi
p = figure(plot_height=350, title="Pie Chart", toolbar_location=None,
tools="hover", tooltips="@country: @value")
p.wedge(x=0, y=1, radius=0.4,start_angle=cumsum('angle', include_zero=True),
end_angle=cumsum('angle'), line_color="white", fill_color='color',
legend_field='country',
source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None
show(p)
AttributeError Traceback (most recent call last)
<ipython-input-17-43a75b324ec9> in <module>
29 end_angle=cumsum('angle'), line_color="white", fill_color='color',
30 legend_field='country',
---> 31 source=data)
32
33 p.axis.axis_label=None
fakesource in wedge(self, x, y, radius, start_angle, end_angle, direction, **kwargs)
~/anaconda3/lib/python3.7/site-packages/bokeh/plotting/helpers.py in func(self, **kwargs)
818 mglyph_ca = None
819
--> 820 glyph = _make_glyph(glyphclass, kwargs, glyph_ca)
821 nsglyph = _make_glyph(glyphclass, kwargs, nsglyph_ca)
822 sglyph = _make_glyph(glyphclass, kwargs, sglyph_ca)
~/anaconda3/lib/python3.7/site-packages/bokeh/plotting/helpers.py in _make_glyph(glyphclass, kws, extra)
359 kws = kws.copy()
360 kws.update(extra)
--> 361 return glyphclass(**kws)
362
363
~/anaconda3/lib/python3.7/site-packages/bokeh/model.py in __init__(self, **kwargs)
259 self._document = None
260 self._temp_document = None
--> 261 super(Model, self).__init__(**kwargs)
262 default_theme.apply_to_model(self)
263
~/anaconda3/lib/python3.7/site-packages/bokeh/core/has_props.py in __init__(self, **properties)
251
252 for name, value in properties.items():
--> 253 setattr(self, name, value)
254
255 def __setattr__(self, name, value):
~/anaconda3/lib/python3.7/site-packages/bokeh/core/has_props.py in __setattr__(self, name, value)
286
287 raise AttributeError("unexpected attribute '%s' to %s, %s attributes are %s" %
--> 288 (name, self.__class__.__name__, text, nice_join(matches)))
289
290 def __str__(self):
AttributeError: unexpected attribute 'legend_field' to Wedge, possible attributes are direction, end_angle, end_angle_units, fill_alpha, fill_color, js_event_callbacks, js_property_callbacks, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, name, radius, radius_units, start_angle, start_angle_units, subscribed_events, tags, x or y`Preformatted text`