需用用到的Python第三方库:pandas、pyecharts。
效果图:
这是3月20日的数据。18个省份连续“零报告”。整理后:
import pandas as pd
from pyecharts.charts import Pie
from pyecharts import options as opts
provinces = ['西藏','青海','贵州','江苏','新疆','内蒙古','海南',
'吉林','重庆','山西','安徽','江西','河北','湖南','宁夏','河南','云南','湖北']
num = [51,44,33,31,31,31,30,26,25,25,23,22,22,22,17,9,4,3]
color_series = ['#C9DA36','#9ECB3C','#6DBC49',
'#3DBA78','#14ADCF','#209AC9',
'#2C6BA0','#2D3D8E','#6A368B'
'#7D3990','#A63F98','#C31C88',
'#D5225B','#D02C2A','#D44C2D',
'#D99D21','#CF7B25''#CF7B25']
df = pd.DataFrame({'provinces': provinces, 'num': num})
df.sort_values(by='num', ascending=False, inplace=True)
a = df['provinces'].values.tolist()
b = df['num'].values.tolist()
pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px'))
pie1.set_colors(color_series)
# 添加数据,设置饼图的半径,是否展示成南丁格尔图
pie1.add("", [list(z) for z in zip(a, b)],
radius=["30%", "135%"],
center=["50%", "65%"],
rosetype="area"
)
# 设置全局配置项
pie1.set_global_opts(title_opts=opts.TitleOpts(title='多省区市确诊病例连续零新增'),
legend_opts=opts.LegendOpts(is_show=False),
toolbox_opts=opts.ToolboxOpts())
# 设置系列配置项
pie1.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="inside", font_size=12,
formatter="{b}:{c}天", font_style="italic",
font_weight="bold", font_family="Microsoft YaHei"
),
)
pie1.render('a.html')