def pie_set_colors(): obj_pie = Pie() obj_pie.add("",[list(z) for z in zip(Faker.choose(), Faker.values())]) obj_pie.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"]) obj_pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) obj_pie.set_global_opts(title_opts=opts.TitleOpts(title="Pie-设置颜色",subtitle ="副标题")) return obj_pie
def show_pie_charts(df): score_perc = df['star'].value_counts() / df['star'].value_counts().sum( ) # 评分占比 = 评分1-5的个数(分别) / 评分总个数 score_perc = np.round(score_perc * 100, 2) score_perc = score_perc.sort_index() # Series也可以排序 # 聚合后类型为Series,转成Dataframe # df_score = pd.DataFrame(list(zip(score_perc.index, score_perc.values)), columns=['score', 'percentage']).sort_values('score') pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) pie1.add( series_name='评分占比', data_pair=[*zip(score_perc.index, score_perc.values) ], # Series: zip打包为一个元组对象,用*解压成元组,再[]转成列表 # data_pair=[*zip(df_score['score'], df_score['percentage'])], # Dataframe label_opts=opts.LabelOpts(formatter='{c}%'), # formatter='{c}%'百分比 radius=['35%', '70%'] # 是什么意思 ) pie1.set_global_opts( title_opts=opts.TitleOpts(title='总体评分分布'), legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%'), # 图例的位置:水平/垂直 toolbox_opts=opts.ToolboxOpts()) # 右上角的工具栏,保存图片等等 pie1.set_colors(['#D7655A', '#FFAF34', '#3B7BA9', '#EF9050', '#6FB27C']) pie1.render('charts/pie_chart.html')
def show_pie(id): attr = ["成功(含熔断)", "失败", "限流"] counts = [len(sync.success), len(sync.fail), sync.limit] c = Pie(init_opts=opts.InitOpts( width='1200px', height='800px', page_title='page')) c.add("", [list(attr) for attr in zip(attr, counts)]) c.set_colors(["green", "red", "blue"]) c.set_global_opts(title_opts=opts.TitleOpts(title="成功失败数量饼图")) c.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) c.render('成功失败数量饼图{}.html'.format(id + 1))
def pieChart(df): def randomcolor(kind): colors = [] for i in range(kind): #colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F','G','H','I','K','L','M','N'] colArr = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] color = '' for i in range(6): color += colArr[random.randint(0, 14)] colors.append('#' + color) return colors all_columns = df.columns type_of_plot = st.selectbox("Select Type of Plot", ["PIE1", "PIE2", "PIE3"]) columns_to_plot = st.selectbox("Select 1 column", all_columns, key='a') columns_to_plot1 = st.selectbox("Select 1 column", all_columns, key='b') if st.button("Generate Plot"): #st.success("Generating Customizable Plot of {} for {}".format(type_of_plot)) if type_of_plot == 'PIE1': cje = df[columns_to_plot].tolist() other_var = df[columns_to_plot1].tolist() color_series = randomcolor(len(cje)) pie = Pie() pie.add('', [list(z) for z in zip(cje, other_var)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') pie.set_global_opts(title_opts=opts.TitleOpts( title='Population Generale des 20 CJE de Montreal'), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts()) pie.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')) pie.set_colors(color_series) return pie
def pyechart_Pie_plot(self, filedata, para): from pyecharts.charts import Pie file_name = '南丁格尔玫瑰图.html' path_plotly = self.path_dir_plotly_html + os.sep + file_name # 文件路径,前面是文件夹后面是文件名 costumeTheme = self.themedict[para['theme']] # ----------------------------------------------------------------------- # 准备数据 df = pd.read_excel(filedata, sheet_name='sheet1') # # 提取数据 v = df['provinces'].values.tolist() d = df['num'].values.tolist() color_series = df['color_series'].values.tolist() # 降序排序 df.sort_values(by='num', ascending=False, inplace=True) # 实例化Pie类 pie1 = Pie(init_opts=opts.InitOpts( theme=costumeTheme, width=para['width'], height=para['height'])) # 设置颜色 pie1.set_colors(color_series) # 添加数据,设置饼图的半径,是否展示成南丁格尔图 pie1.add("", [list(z) for z in zip(v, d)], radius=["10%", "135%"], center=["50%", "65%"], rosetype="area") # 设置全局配置项 pie1.set_global_opts( title_opts=opts.TitleOpts(title=para["title"], subtitle=para["subtitle"]), toolbox_opts=opts.ToolboxOpts(feature=opts.ToolBoxFeatureOpts( save_as_image=opts.ToolBoxFeatureSaveAsImageOpts( background_color="white"))) #visualmap_opts=opts.VisualMapOpts(), ) # 设置系列配置项 pie1.set_series_opts( label_opts=opts.LabelOpts( is_show=True, position="inside", font_size=12, formatter="{b}:{c}天", font_style="normal", # css的格式 font_weight="normal", font_family="宋体"), ) # 生成html文档 pie1.render(path_plotly) return path_plotly # 返回该HTML文件路径
def draw(list1, list2): pie = Pie() pie.add("", list(zip(list1, list2))) pie.set_global_opts( title_opts=opts.TitleOpts(title="消费者购买的HUAWEIP30颜色图例"), #标题 legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="4%"), ) pie.set_series_opts( label_opts=opts.LabelOpts(formatter="{b}: {c}")) #图例显示(颜色+人数),例:亮黑色:46 pie.set_colors( ["lightblue", "black", "turquoise", "orangered", "lightpink"]) pie.render(desktop + "\\jd.huaweiP30.html") return True
def show_pie_charts(): score_perc = df['rating'].value_counts() / df['rating'].value_counts().sum( ) score_perc = np.round(score_perc * 100, 2) print(score_perc) pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) pie1.add("", [*zip(score_perc.index, score_perc.values)], radius=["35%", "70%"]) pie1.set_global_opts(title_opts=opts.TitleOpts(title='总体评分分布'), legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"), toolbox_opts=opts.ToolboxOpts()) pie1.set_series_opts(label_opts=opts.LabelOpts(formatter="{c}%")) pie1.set_colors(['#D7655A', '#FFAF34', '#3B7BA9', '#EF9050', '#6FB27C']) pie1.render()
def pie_base(data1, data2) -> Pie: list_color = ['#990033', '#990000', '#CC0066', '#CC0033', '#CC0000', '#FF0000', 'FF00FF', 'FF1493', '#FF4500', '#FF6347'] pie = Pie() pie.add( series_name="", data_pair=[list(z) for z in zip(data1, data2)], radius=["20%", "75%"], rosetype="area", label_opts=opts.LabelOpts(is_show=False), ) pie.set_colors(list_color) pie.set_global_opts( title_opts=opts.TitleOpts(title="", title_textstyle_opts=(opts.TextStyleOpts(color='white'))), legend_opts=opts.LegendOpts(is_show=False)) return pie
def Cartography(): #创建地图 map = Map( init_opts=opts.InitOpts(width="1900px", height="900px", bg_color="#d0effa", page_title="全球新冠疫情_1")) map.add("确诊人数",[list(z) for z in zip(names_new, confirm)],is_map_symbol_show=False, maptype="world",label_opts=opts.LabelOpts(is_show=False),itemstyle_opts=opts.ItemStyleOpts(color="rgb(98,121,146)"))#地图区域颜色 map.set_global_opts(title_opts = opts.TitleOpts(title='全球新冠疫情确诊人数'),legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=2000000, is_piecewise=True, pieces=[ {"max": 3000000,"min": 500001,"label":">500000","color":"#460303"}, {"max": 500000, "min": 100001, "label": "100001-500000", "color": "#8A0808"}, {"max": 100000, "min": 10001, "label": "10001-100000", "color": "#B40404"}, {"max": 10000, "min": 1001, "label": "1001-10000", "color": "#DF0101"}, {"max": 1000, "min": 101, "label": "101-1000", "color": "#F78181"}, {"max": 100, "min": 1, "label": "1-100", "color": "#F5A9A9"}, {"max": 0, "min": 0, "label": "0", "color": "#fababa"}, ]) ) map.render('Global_new_crown_epidemic_map.html') #创建饼图 pie = Pie(init_opts=opts.InitOpts(width='1900px', height='900px',page_title="全球新冠疫情_2",bg_color="#fee4e7")) # 添加数据 pie.add("", [list(z) for z in zip(country_list, dead_list)], radius=['20%', '100%'],#设置内径外径 center=['60%', '65%'], rosetype='area')#圆心角相同,通过半径展现数据大小#rosetype='radius'圆心角展现数据百分比,半径展现数据大小 # 设置全局配置 pie.set_global_opts(title_opts=opts.TitleOpts(title='全球新冠疫情',subtitle='死亡人数超过\n5000的国家\n (除中国)', title_textstyle_opts=opts.TextStyleOpts(font_size=15,color= '#f40909'), subtitle_textstyle_opts= opts.TextStyleOpts(font_size=15,color= '#8a0b0b'), pos_right= 'center',pos_left= '57%',pos_top= '60%',pos_bottom='center'), legend_opts=opts.LegendOpts(is_show=False)) # 设置系列配置和颜色 pie.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=13, formatter='{b}:{c}', font_style='italic', font_family='Microsoft YaHei')) pie.set_colors(color_matching) pie.render('Global_new_crown_epidemic_Rose.html') #创建雷达图 radar = Radar(init_opts=opts.InitOpts(width='1900px',height='900px',page_title="全球新冠疫情_3",bg_color="#d1eff3")) #由于雷达图传入的数据得为多维数据,所以这里需要做一下处理 radar_data1 = [list(dead_list)] radar_data2 = [list(heal_list)] radar.add_schema( schema=[ opts.RadarIndicatorItem(name='巴西', max_=8000), opts.RadarIndicatorItem(name='荷兰', max_=8000), opts.RadarIndicatorItem(name='伊朗', max_=20000), opts.RadarIndicatorItem(name='德国', max_=40000), opts.RadarIndicatorItem(name='比利时', max_=70000), opts.RadarIndicatorItem(name='英国', max_=80000), opts.RadarIndicatorItem(name='法国 ', max_=110000), opts.RadarIndicatorItem(name='西班牙', max_=150000), opts.RadarIndicatorItem(name='意大利', max_=170000), opts.RadarIndicatorItem(name='美国', max_=220000), ] ) radar.add("死亡人数",radar_data1,color='blue',areastyle_opts = opts.AreaStyleOpts(opacity = 0.2,color='blue')) radar.add("治愈人数",radar_data2,color='red',areastyle_opts=opts.AreaStyleOpts(opacity=0.3,color='red')) radar.set_series_opts(label_opts=opts.LabelOpts(is_show=True)) radar.set_global_opts(title_opts=opts.TitleOpts(title="死亡人数与治愈人数对比")) radar.render("Death_Versus_Heal.html")
'#D44C2D', '#F57A34', '#FA8F2F', '#D99D21', '#CF7B25', '#CF7B25', '#CF7B25' ] # Create data box df = pd.DataFrame({'provinces': provinces, 'num': num}) # Descending sort df.sort_values(by='num', ascending=False, inplace=True) # Extract data v = df['provinces'].values.tolist() d = df['num'].values.tolist() # Instantiate the Pie class pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) # Set color pie1.set_colors(color_series) # Add data, set the radius of pie chart, and show it as Nightingale chart or not pie1.add("", [list(z) for z in zip(v, d)], radius=["30%", "135%"], center=["50%", "65%"], rosetype="area") # Set global configuration item pie1.set_global_opts(title_opts=opts.TitleOpts(title='Rose chart example'), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts()) # Set series configuration items pie1.set_series_opts(label_opts=opts.LabelOpts( is_show=True, position="inside", font_size=12, formatter="{b}:{c}day",
bg_color='white')) pie.add('', [list(z) for z in zip(provinces, numbers)], radius=['30%', '115%'], center=['40%', '50%'], rosetype='radius') pie.set_global_opts(title_opts=opts.TitleOpts(title='广东省2020年1月-6月最高负荷平方根(兆瓦)', pos_left='25%', pos_top='5%'), legend_opts=opts.LegendOpts(is_show=False, pos_top='12%', pos_left='12%', orient='vertical', align='auto')) # pie.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=12, formatter='{b}:{c}', font_family='Microsoft YaHei')) pie.set_series_opts(label_opts=opts.LabelOpts(is_show=False, position='inside', font_size=12, font_family='Microsoft YaHei')) pie.set_colors(colors) # pie.render('广东省2020年1月-6月最高负荷平方根(radius).html') make_snapshot(snapshot, pie.render(), "广东省2020年1月-6月最高负荷平方根(radius).png", pixel_ratio=13, is_remove_html=True)
# 绘制饼图可以清晰地看出各价格区间货品销售额在总体占比情况: data_pair = [ list(z) for z in zip(cut_purchase.index.tolist(), cut_purchase.values.tolist()) ] # 绘制饼图 pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) pie1.add('', data_pair, radius=['35%', '60%']) pie1.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的销售额整体表现'), legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%')) pie1.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%")) pie1.set_colors([ '#EF9050', '#3B7BA9', '#6FB27C', '#FFAF34', '#D8BFD8', '#00BFFF', '#7FFFAA' ]) pie1.render() # 玩一个词云图 def get_cut_words(content_series): # 读入停用词表 stop_words = [] with open( r"C:/Users/Maggie/Desktop/Udemy-desktop/xiaoxiangxueyuan/Python认知打卡课课程资料包/资料代码整理/数据分析/解读乐高/stop_words.txt", 'r', encoding='utf-8') as f: lines = f.readlines() for line in lines: stop_words.append(line.strip())
def foregin_city_all(): path = readPath + '/各国各地区疫情信息' path2 = savaPath + '/各国疫情严重程度排名前十地区信息' dwf.createFile(path2) Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) # 随机颜色生成用于制作南丁格尔玫瑰图 def randomcolor(kind): colors = [] for i in range(kind): colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] color = "" for i in range(6): color += colArr[random.randint(0, 14)] colors.append("#" + color) return colors for i in Filelist: page1 = Page() data = pd.read_excel(readPath + '/各国各地区疫情信息/%s' % (i), index=False) data_sort = data.sort_values(axis=0, ascending=False, by=['confirm']) data_message = data_sort.head(10) # 提取疫情严重程度排名前十地区的信息 n = i[:-5] # 只提取国家名,不要后缀(.xlsx) checknan(data_message['confirm']) checknan(data_message['heal']) checknan(data_message['dead']) y1_confirm = data_message['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_dead = data_message['dead'] y2_dead = list(y2_dead) y2_dead = [int(i) for i in y2_dead] y3_heal = data_message['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] name_list = [] for j in data_message['name']: name_list.append(j) x = name_list color_series = randomcolor(len(x)) # Bars = ( # Bar(init_opts=opts.InitOpts(width='1080px',height='700px')) # .add_xaxis(xaxis_data=x) # .add_yaxis(series_name='确诊人数', yaxis_data=y1_confirm) # ) #####画南丁格尔玫瑰图########## # 画出确诊人数的图 fig = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig.add("", [list(z) for z in zip(x, y1_confirm)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的确诊人数'), legend_opts=opts.LegendOpts(is_show=False)) fig.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')) # b:province;c:num fig.set_colors(color_series) # 画出死亡人数的图 fig1 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig1.add("", [list(z) for z in zip(x, y2_dead)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig1.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的死亡人数'), legend_opts=opts.LegendOpts(is_show=False)) fig1.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')) # b:province;c:num # 画出治愈人数的图 fig2 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig2.add("", [list(z) for z in zip(x, y3_heal)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig2.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的治愈人数'), legend_opts=opts.LegendOpts(is_show=False)) fig2.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')) # b:province;c:num page1.add(fig) # 将图像加入同一页 page1.add(fig1) # 将图像加入同一页 page1.add(fig2) # 将图像加入同一页 page1.render(savaPath + '/各国疫情严重程度排名前十地区信息/%s.html' % (n), index=False) if flag: dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(确诊)%s.txt' % (n),str(fig.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(死亡)%s.txt' % (n),str(fig1.dump_options_with_quotes())) dwf.write_to_file(savaPath + '/各国疫情严重程度排名前十地区信息/(治愈)%s.txt' % (n),str(fig2.dump_options_with_quotes()))
border_color="#aaa", border_width=1, border_radius=4, rich={ "a": {"color": "#999", "lineHeight": 22, "align": "center"}, "abg": { "backgroundColor": "#e3e3e3", "width": "100%", "align": "right", "height": 22, "borderRadius": [4, 4, 0, 0], }, "hr": { "borderColor": "#aaa", "width": "100%", "borderWidth": 0.5, "height": 0, }, "b": {"fontSize": 16, "lineHeight": 33}, "per": { "color": "#eee", "backgroundColor": "#334455", "padding": [2, 4], "borderRadius": 2, }, }, ), ) pie.set_global_opts(title_opts=opts.TitleOpts(title='职业占比')) pie.set_colors(['red', 'orange', 'purple']) # 设置颜色 pie.render('美女职业分布.html')
) df = df.sort_values('no_trails') #, ascending=False) # Nightingale Rose Chart c = df['region'].values.tolist() d = df['no_trails'].values.tolist() #create the color_series for the rosechart # define rosechart rosechart = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) # set the color color_series = [ '#802200', '#B33000', '#FF4500', '#FAA327', '#9ECB3C', '#6DBC49', '#37B44E', '#14ADCF', '#209AC9', '#1E91CA', '#2C6BA0', '#2B55A1', '#2D3D8E', '#44388E', '#6A368B', '#D02C2A', '#D44C2D', '#F57A34', '#FA8F2F', '#D99D21' ] rosechart.set_colors(color_series) # add the data to the rosechart rosechart.add( "", [list(z) for z in zip(c, d)], radius=["20%", "95%"], # 20% inside radius,95% ourside radius center=["30%", "60%"], # center of the chart rosetype="area") # set the global options for the chart rosechart.set_global_opts( title_opts=opts.TitleOpts(title='Washington Trails', subtitle="# of Trails by Region"), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts()) # set the series options rosechart.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="inside", font_size=12,
sex_num.drop('保密', inplace=True) print(sex_num) #男性观众4537人,女性观众3759人 # 绘制饼图 data_pair = [ list(z) for z in zip(sex_num.index.tolist(), sex_num.values.tolist()) ] # 绘制饼图 pie1 = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) pie1.add('', data_pair, radius=['35%', '60%']) pie1.set_global_opts(title_opts=opts.TitleOpts(title='评论用户性别占比'), legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%')) pie1.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%")) pie1.set_colors(['#EF9050', '#3B7BA9', '#6FB27C']) pie1.render( ) #generate a file:///C:/Users/Maggie/Desktop/Udemy-desktop/xiaoxiangxueyuan/pythonCases/xiaoxiang_projects/python_in_16_days/render.html # 这次我们需要操作的是‘设备’这一列的数据。 device_num = df.设备.value_counts(ascending=True) print(device_num) # 绘制一个柱状图来展示一下 # 柱形图 bar1 = Bar(init_opts=opts.InitOpts(width='1350px', height='750px')) bar1.add_xaxis(device_num.index.tolist()) bar1.add_yaxis('', device_num.values.tolist(), label_opts=opts.LabelOpts(position='right')) bar1.set_global_opts(title_opts=opts.TitleOpts(title='评论客户端分布'),
def foregin_city_all(): file = os.getcwd() # 读取当前文件路径 path = file + '\\data\\各国各地区疫情信息' path1 = file + '\\daliy_changes_view' isExists = os.path.exists(path1) # 判断当前目录是否有文件夹photos,如果没有则创建 if not isExists: os.mkdir(path1) # 创建photos,用于存放生成的图像数据 path2 = file + '\\daliy_changes_view\\各国疫情严重程度排名前十地区信息' isExists = os.path.exists(path2) # 判断当前目录是否有文件夹daliy_changes_view,如果没有则创建 if not isExists: os.mkdir(path2) # 创建daliy_changes_view,用于存放生成的图像数据 Filelist = [] # 将当前文件夹内的所有表名存放此列表 for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) # 判断数据是否存在 def checknan(name): if np.any(pd.isnull(name)) == True: name.fillna(value="0", inplace=True) # 随机颜色生成用于制作南丁格尔玫瑰图 def randomcolor(kind): colors = [] for i in range(kind): colArr = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ] color = "" for i in range(6): color += colArr[random.randint(0, 14)] colors.append("#" + color) return colors for i in Filelist: data = pd.read_excel(file + '\\data\\各国各地区疫情信息\\%s' % (i), index=False) data_sort = data.sort_values(axis=0, ascending=False, by=['confirm']) data_message = data_sort.head(10) # 提取疫情严重程度排名前十地区的信息 n = i[:-5] # 只提取国家名,不要后缀(.xlsx) checknan(data_message['confirm']) checknan(data_message['heal']) checknan(data_message['dead']) y1_confirm = data_message['confirm'] y1_confirm = list(y1_confirm) y1_confirm = [int(i) for i in y1_confirm] y2_dead = data_message['dead'] y2_dead = list(y2_dead) y2_dead = [int(i) for i in y2_dead] y3_heal = data_message['heal'] y3_heal = list(y3_heal) y3_heal = [int(i) for i in y3_heal] name_list = [] for j in data_message['name']: name_list.append(j) x = name_list color_series = randomcolor(len(x)) # Bars = ( # Bar(init_opts=opts.InitOpts(width='1080px',height='700px')) # .add_xaxis(xaxis_data=x) # .add_yaxis(series_name='确诊人数', yaxis_data=y1_confirm) # ) page = Page() # 创建一个分页用于放所有的图像在这一分页上 #####画南丁格尔玫瑰图########## # 画出确诊人数的图 fig = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig.add("", [list(z) for z in zip(x, y1_confirm)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的确诊人数'), legend_opts=opts.LegendOpts(is_show=False)) fig.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')) # b:province;c:num fig.set_colors(color_series) # 画出死亡人数的图 fig1 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig1.add("", [list(z) for z in zip(x, y2_dead)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig1.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的死亡人数'), legend_opts=opts.LegendOpts(is_show=False)) fig1.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')) # b:province;c:num # 画出治愈人数的图 fig2 = Pie(init_opts=opts.InitOpts(width='500px', height='700px')) fig2.add("", [list(z) for z in zip(x, y3_heal)], radius=['30%', '135%'], center=['50%', '65%'], rosetype='area') fig2.set_global_opts(title_opts=opts.TitleOpts(title=n + '疫情严重程度排名前十地区的治愈人数'), legend_opts=opts.LegendOpts(is_show=False)) fig2.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')) # b:province;c:num page.add(fig) # 将图像加入同一页 page.add(fig1) # 将图像加入同一页 page.add(fig2) # 将图像加入同一页 page.render_notebook() page.render(file + '\\daliy_changes_view\\各国疫情严重程度排名前十地区信息\\%s.html' % (n), index=False)