def map_visualmap(sumary) -> Map: c = ( Map(init_opts=InitOpts(width="750px", height='1000px')).add( "确诊", sumary, "上海", is_map_symbol_show=False, label_opts=None).set_global_opts( title_opts=TitleOpts( title="分布统计(不含外地来沪和待确认)", subtitle=' 市卫健局每日两次发布信息,如未更新,请尝试刷新页面', pos_left='10%', pos_top='top', title_textstyle_opts=TextStyleOpts(font_size=40), subtitle_textstyle_opts=TextStyleOpts(font_size=20), ), visualmap_opts=VisualMapOpts( max_=70, range_color=['lightblue', 'yellow', 'red'], pos_top='15%', pos_left='12%', item_height='200px', item_width='30px', textstyle_opts=TextStyleOpts(font_size=15) # split_number=50 ), legend_opts=LegendOpts(is_show=False), tooltip_opts=TooltipOpts(textstyle_opts=TextStyleOpts( font_size=30)), )) return c
def calendar_base() -> Calendar: # begin = datetime.date(2020,1,19) # end = datetime.date(2020,3,1) # data = [ # [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)] # for i in range((end - begin).days + 1) # al # print(data) c = ( Calendar(init_opts=InitOpts( width="100%")) .add( "", new_date, calendar_opts=CalendarOpts( range_=['2020-1-15', '2020-3-1'], orient="vertical", pos_left=None, pos_right=None, pos_bottom=None, pos_top=None # daylabel_opts=LabelOpts( # font_size=10 # ) ) ) .set_global_opts( title_opts=TitleOpts( title="新增病例时间分布图", pos_left='center',pos_top='bottom', title_textstyle_opts=TextStyleOpts(font_size=40), ), visualmap_opts=VisualMapOpts( max_=40,min_=1, orient="vertical", range_color=['white','yellow','red'], # is_piecewise=True, pos_top="230px", pos_left="100px", item_height='200px',item_width='30px', ), ) ) return c
range_start=50, range_end=100, ), ], "tooltip_opts": TooltipOpts(is_show=True, trigger="axis", trigger_on="mousemove", axis_pointer_type="cross"), } heatmap_opts = { "visualmap_opts": VisualMapOpts(min_=-1, max_=1, orient="horizontal", pos_right="middle", pos_top="bottom") } # pie_opts = { # "tooltip_opts": TooltipOpts(), # "legend_opts": LegendOpts(orient="vertical", pos_left="left"), # } themeriver_opts = { "xaxis_opts": AxisOpts(type_="time"), "datazoom_opts": [DataZoomOpts(range_start=60, range_end=100)], "tooltip_opts": TooltipOpts(trigger_on="mousemove", trigger="item"), "legend_opts": LegendOpts(pos_top="top"), }
addr_dic[provice] = 0 addr_dic[provice] += 1 # print(addr_dic) # print(addr_dic.items()) sort_addr = sorted(addr_dic.items(), key=lambda item: item[1], reverse=True)[0:10] print(sort_addr) # addr_names = [item[0] for item in sort_addr] # addr_counts = [item[1] for item in sort_addr] # print(addr_names, addr_counts) from pyecharts.charts import Geo from pyecharts.options import LabelOpts, VisualMapOpts, TitleOpts from pyecharts.globals import ChartType geo = Geo() geo.add_schema(maptype="china") geo.add("地点统计", sort_addr, type_=ChartType.EFFECT_SCATTER) geo.set_series_opts(label_opts=LabelOpts(is_show=False)) geo.set_global_opts( visualmap_opts=VisualMapOpts(is_piecewise=True, max_=sort_addr[0][1]), title_opts=TitleOpts(title="撩课Python统计"), ) geo.render("地点统计-geo图.html")
def wechat_friends_analysis(cls, friends): # print(itchat.get_friends()[1]) analysis = cls.toggle.analysis if not analysis.isAllEnabled: print( "================= analysis not allow friends analysis skip ================" ) return provinces, province_count, cities, city_count = [], [], [], [] tuple_city_list = cls.wechat_information_refine( "City", friends, 3, True) tuple_province_list = cls.wechat_information_refine( "Province", friends, 4, True) if analysis.sexAnalysis: sex_title = ["未知", "男", "女"] remark_sex_count = [0, 0, 0] no_remark_sex_count = [0, 0, 0] for friend in friends: sex = friend["Sex"] if len(friend["RemarkName"]): remark_sex_count[sex] += 1 else: no_remark_sex_count[sex] += 1 for i, j in tuple_province_list: if not len(i): i = "未知" provinces.append(i) province_count.append(j) for i, j in tuple_city_list: if not len(i): i = "未知" cities.append(i) city_count.append(j) # print(cities, city_count) # print(provinces, province_count) page_title = "好友性别数据统计" bar_sex = Bar(init_opts=InitOpts(page_title=page_title)) bar_sex.add_xaxis(sex_title) bar_sex.add_yaxis("有备注", remark_sex_count) bar_sex.add_yaxis("无备注", no_remark_sex_count) bar_sex.set_global_opts( title_opts=TitleOpts(title="微信好友性别数据统计", pos_left="60")) bar_sex.render("sex.html") if analysis.barCity: bar_city = Bar() bar_city.add_xaxis(cities) bar_city.add_yaxis("微信好友地区数据统计", city_count) bar_city.set_global_opts(toolbox_opts=ToolboxOpts(is_show=True)) bar_city.render("city.html") if analysis.barProvince: bar_province = (Bar().add_xaxis(provinces).add_yaxis( "微信好友省份统计", province_count).set_global_opts( toolbox_opts=ToolboxOpts(is_show=True))) try: make_snapshot(snapshot, bar_province.render("bar_province.html"), "bar_province.png") except Exception as e: print("make snap shot error", e) else: bar_province.render("bar_province") if analysis.pieCity: city_data_list = [(i, j) for i, j in zip(cities, city_count)] pie_city = ( Pie(init_opts=InitOpts( page_title="微信好友城市分析", width="1400px", height="800px", )).add( data_pair=city_data_list, series_name="微信好友分布", # radius=["25%", "75%"], # rosetype="radius" ).set_global_opts(toolbox_opts=ToolboxOpts(is_show=True, pos_top="50px"), title_opts=TitleOpts(title="微信好友城市分析", pos_top="80px", pos_left="10px")) # .render("pie_city.html") ) try: make_snapshot(snapshot, pie_city.render("pie_city.html"), "pie_city.png") except Exception as e: print("make snap shot error", e) else: pie_city.render("pie_city.html") if analysis.pieProvince: province_data_list = [(i, j) for i, j in zip(provinces, province_count)] pie_province = ( Pie(init_opts=InitOpts( page_title="微信好友省份分析", width="1200px", height="800px", )).add(data_pair=province_data_list, series_name="微信好友分布", radius=["25%", "75%"], rosetype="Mapping").set_global_opts( toolbox_opts=ToolboxOpts(is_show=True, pos_top="60px"), title_opts=TitleOpts(title="微信好友省份分析", pos_top="60px", pos_left="50px")) # .render("pie_province.html") ) try: make_snapshot(snapshot, pie_province.render("pie_province.html"), "pie_province.png") except Exception as e: print("make snap shot error", e) else: pie_province.render("pie_province.html") if analysis.geoProvince: province_geo = ( Map(init_opts=InitOpts(page_title="微信好友分布")).add( "微信好友分布geo图", tuple_province_list, "china").set_global_opts( title_opts=TitleOpts(title="微信好友分布分布", pos_left="30px"), visualmap_opts=VisualMapOpts(max_=600, split_number=5, is_piecewise=True)) # .render("geo_province.html") ) try: make_snapshot(snapshot, province_geo.render("geo_province.html"), "geo_province.png") except Exception as e: print("make snap shot error", e) else: province_geo.render("province_geo.html") print( "============================= wechat friends analysis success =============================" )