用pyecharts画柱状图
from pyecharts import options as opts
from pyecharts.charts import Bar
hamburger = {
'热量' : 250,
'脂肪' : 10,
'碳水化合物' : 20,
'蛋白质' : 10
}
x = ['汉堡','饭团','粥','鸡肉']
y1 = [250,200,50,255]
y2 = [10,11,1.5,15]
y3 = [20,21,8,10]
y4 = [10,6,2.5,21]
c = Bar()
c.add_xaxis(x)
c.add_yaxis("热量", y1, stack="stack1")
c.add_yaxis("脂肪", y2, stack="stack1")
c.add_yaxis("碳水化合物", y3, stack="stack1")
c.add_yaxis("蛋白质", y4, stack="stack1")
c.set_series_opts(label_opts=opts.LabelOpts(is_show=False),
)
c.set_global_opts(title_opts=opts.TitleOpts(title="主食营养分布"),
)
c.render('主食营养分布.html')
用pyechats画饼状图
from pyecharts import options as opts
from pyecharts.charts import Bar,Pie
c = Pie()
c.add(
"",
[list(z) for z in zip(["热量", "脂肪",'碳水化合物','蛋白质'],
[31,2,1.5, 3])],
center=["20%", "50%"],
radius=[60, 80],
)
c.add(
"",
[list(z) for z in zip(["热量", "脂肪",'碳水化合物','蛋白质'],
[100,4,12, 4])],
center=["55%", "50%"],
radius=[60, 80],
)
c.set_global_opts(
title_opts=opts.TitleOpts(title="豆浆(左)咖啡(右)"),
legend_opts=opts.LegendOpts(
type_="scroll", pos_top="200%", pos_left="80%", orient="vertical"
),
)
c.set_series_opts(
tooltip_opts=opts.TooltipOpts(
trigger="item", formatter="{a}
{b}: {c} ({d}%)"
))
c.render('豆浆咖啡.html')