1.绘制饼图
import numpy as np
import pyecharts.options as opts
from pyecharts.charts import Pie
data = [("化学药",33),("中成药",45),("生物制品",3),("保健品",9),("中药饮片",6),("其他",4)]
pie = Pie()
pie.add("",data)
pie.set_global_opts(title_opts=opts.TitleOpts(title="全国药店药品销售额占比"))
pie.render_notebook()
代码运行结果:
2.绘制圆环图
from pyecharts import options as opts
from pyecharts.charts import Page, Pie
#准备数据
wd = ['化学药','中成药','生物制品','保健品','中药饮片']
num = [33,45,3,9,6,4]
#往实例中填充数据
pie= Pie()
pie.add("",[list(z) for z in zip(wd, num)],radius = ["40%", "75%"])
# 圆环的粗细和大小
pie.set_global_opts( title_opts=opts.TitleOpts(title="全国药店药品销售额占比",subtitle='用于反映中药市场趋势'),legend_opts=opts.LegendOpts(is_show=False),toolbox_opts=opts.ToolboxOpts(is_show=True))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))
# 展示图表
pie.render_notebook()
代码运行结果: