结果截图
数据准备
数据的爬取:https://www.cnblogs.com/qi-6666/p/15525301.html
导入库
from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.globals import ChartType, SymbolType from pyecharts.charts import Map import pandas as pd from pyecharts.charts import Bar from pyecharts.globals import ThemeType from pyecharts.charts import Map,Page
玫瑰图(使用软件:jupyter python3)
from pyecharts import options as opts import pandas as pd data_age = pd.read_excel('实时更新:新型冠状病毒肺炎疫情地图3.xlsx') # 年龄数据分箱 data_age['确诊区间'] = pd.cut(data_age['确诊数'], bins = [0,60,120,200], labels = ['60以下','60-120','120以上']) # data_age # 年龄区间数量统计 age_counts = data_age['确诊区间'].value_counts() # age_counts # 数据结构重组 charts_data_age = [z for z in zip(age_counts.index,age_counts.tolist())] from pyecharts.charts import Pie from pyecharts.globals import ThemeType pie = ( Pie(init_opts=opts.InitOpts(width="600px", height="400px",theme=ThemeType.DARK)) # 设置背景的大小 .add( series_name = "确诊数", # 必须项 data_pair = charts_data_age, radius=["20%", "50%"], # 设置环的大小 rosetype="radius", # 设置玫瑰图类型 label_opts=opts.LabelOpts(formatter="{a}:{b}\n个数:{c}\n占比:{d}%"), # 设置标签内容格式 ) .set_global_opts(title_opts=opts.TitleOpts(title="确诊比例")) ) pie.render_notebook()
运行结果
(点赞关注后续更新!如遇错误,欢迎截图评论,作者看到会尽力帮解决和更新内容)