Python 3.x 从JSON文件在bokeh中创建piechart
我需要读取一个JSON数据文件并在上面创建一个图表。我知道我必须使用熊猫数据帧 我的JSON看起来像Python 3.x 从JSON文件在bokeh中创建piechart,python-3.x,jupyter-notebook,data-visualization,bokeh,Python 3.x,Jupyter Notebook,Data Visualization,Bokeh,我需要读取一个JSON数据文件并在上面创建一个图表。我知道我必须使用熊猫数据帧 我的JSON看起来像 [ { "name": "Anand", "task": "development", }, ..... ] 迄今为止的代码 from bokeh.charts import donut,show,output_file from bokeh.charts.utils import df_from_json import
[ {
"name": "Anand",
"task": "development",
},
.....
]
迄今为止的代码
from bokeh.charts import donut,show,output_file
from bokeh.charts.utils import df_from_json
import pandas as pd
df=df_from_json('the path of the file')
d= Donut(df,label=['name', 'task'],values='task',text_font_size='8pt')
output_file("donut.html")
show(d)
您可以直接使用
wedge
:
from math import pi
from bokeh.plotting import figure, output_file, show
p = figure(x_range=(-1.2, 1.2), y_range=(-1.2, 1.2))
p.wedge(x=0 , y=0, radius=1, start_angle=0, end_angle=0.75*pi, color="red")
p.wedge(x=0 , y=0, radius=1, start_angle=0.75*pi, end_angle=1.05*pi, color="blue")
p.wedge(x=0 , y=0, radius=1, start_angle=1.05*pi, end_angle=1.55*pi, color="green")
p.wedge(x=0 , y=0, radius=1, start_angle=1.55*pi, end_angle=2*pi, color="orange")
output_file("foo.html")
show(p)
在这里,我分别调用了wedge
,但您也可以将所有数据放入数组/列中,并将所有内容传递给单个调用wedge