import pandas as pd
student = pd.read_csv("student.csv")
from math import pi
import pandas as pd
from bokeh.io import push_notebook, show, output_notebook
from bokeh.palettes import Category20c
from bokeh.layouts import row
from bokeh.plotting import figure
from bokeh.transform import cumsum
output_notebook()
x=student['Mjob'].value_counts()
data = pd.Series(x).reset_index(name='value').rename(columns={'index':'job'})
data
data['angle'] = data['value']/data['value'].sum() * 2*pi
data['angle']
data['color'] = Category20c[len(x)]
data['color']
z=110*(data['value']/data['value'].sum())
data['value']=z
data
p = figure(plot_height=350, title="", toolbar_location=None,
tools="hover", tooltips="@job: @value{0.2f} %", x_range=(-.5, .5))
p.annular_wedge(x=0, y=1, inner_radius=0.15, outer_radius=0.25, direction="anticlock",
start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='job', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None
show(p)
Let's make a Donut Chart with a half circle
x=student['Mjob'].value_counts()
data = pd.Series(x).reset_index(name='value').rename(columns={'index':'job'})
data
We need then to divide only by $\pi$ instead of $2\pi$
data['angle'] = data['value']/data['value'].sum() * pi
data['angle'].sum()
z=110*(data['value']/data['value'].sum())
data['value']=z
data['color'] = Category20c[len(x)]
data
p = figure(plot_height=350, title="", toolbar_location=None,
tools="hover", tooltips="@job: @value{0.2f} %", x_range=(-.5, .5))
p.annular_wedge(x=0, y=0, inner_radius=0.15, outer_radius=0.25, direction="anticlock",
start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='job', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None
show(p)