艰难做了新的作业练习…记录一下
from pyecharts import options as opts
from pyecharts.charts import Pie,Page
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
x_data=["金融","医疗保健","市场业","零售业","制造业","司法","工程与科学","保险业","其他"]
y_data=[172,136,135,101,80,68,50,29,41]
data_pie=[list(i) for i in zip(x_data,y_data)]
def pie_charts() -> Pie:#绘制饼图
c1=(Pie(init_opts=opts.InitOpts(width='1000px',height='600px'))#设置大小
.add("",data_pie)#添加数据
.set_global_opts(title_opts=opts.TitleOpts(title="感兴趣的数据领域",pos_left='center',pos_top=20))#设置标题
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{d}%'))#设置显示格式为百分比
)
return c1
def pie_radius_charts()-> Pie:
#绘制环形图
c2=(Pie(init_opts=opts.InitOpts(width='1000px',height='600px'))#设置大小
.add("",data_pie,radius=['40%','75%'])#设置内外半径
.set_global_opts(title_opts=opts.TitleOpts(title="感兴趣的数据领域",pos_left='center',pos_top=20))#设置标题
.set_series_opts(label_opts=opts.LabelOpts(formatter='{b}:{d}%'))#设置显示格式为百分比
)
return c2
def creatPage():
page=Page(layout=Page.DraggablePageLayout)
page.add(
pie_charts(),
pie_radius_charts()
)
page.render("lxy.html")
if __name__ == "__main__":
creatPage()