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 render_html(self) -> str: """渲染html""" pie = Pie(init_opts=InitOpts(theme=ThemeType.LIGHT)) pie.add('KeyWords', self.result.items()) # pie.set_global_opts(title_opts=TitleOpts(title='主标题', subtitle='附标题')) html = CacheModule.create_cache_path('html') pie.render(html) self.htmlpath = html return html
def working_analysis(title_list, working_list, leave_list, other_list): bar = (Bar( init_opts=InitOpts(page_title="中软汇丰业务线返工人数分析", width="1000px") ).add_xaxis(title_list).add_yaxis( "返工人数", working_list, stack="stack1", category_gap="50%").add_yaxis( "休假人数", leave_list, stack="stack1", category_gap="50%").add_yaxis( "其他人数", other_list, stack="stack1", category_gap="50%").set_series_opts(label_opts=LabelOpts( is_show=False)).set_global_opts( toolbox_opts=ToolboxOpts(is_show=True), title_opts=TitleOpts(title="业务线返工情况数据统计"), legend_opts=LegendOpts(), xaxis_opts=AxisOpts(axislabel_opts=LabelOpts( rotate=45)), ).render("开工情况_bar.html")) line = (Line( init_opts=InitOpts(page_title="中软汇丰业务线返工人数分析", width="1000px") ).add_xaxis(title_list).add_yaxis("返工人数", working_list).add_yaxis( "休假人数", leave_list).add_yaxis("其他人数", other_list).set_global_opts( toolbox_opts=ToolboxOpts(is_show=True), title_opts=TitleOpts(title="业务线返工情况数据统计"), legend_opts=LegendOpts()).render("开工情况_line.html"))
def new_trend(day, newconfirmed, newpending) -> Line: line = ( Line(init_opts=InitOpts()).add_xaxis(day).add_yaxis( '新确诊', newconfirmed, symbol_size=1, # symbol='diamond',color='red', # is_symbol_show = False, itemstyle_opts=ItemStyleOpts(color='red'), label_opts=LabelOpts(font_size=15, color='darkred', position='inside'), linestyle_opts=LineStyleOpts(width=2, color='red'), is_connect_nones=True, is_smooth=True, ) # .add_yaxis( # '新疑似',newpending,symbol_size=1, # # symbol='triangle',color='blue', # itemstyle_opts=ItemStyleOpts(color='blue'), # label_opts=LabelOpts(font_size=15,color='darkblue',position='inside'), # linestyle_opts=LineStyleOpts(width=2,color='blue'), # is_connect_nones=True,is_smooth=True, # ) .set_global_opts( xaxis_opts=AxisOpts( # type_="category", axislabel_opts=LabelOpts(is_show=False), ), yaxis_opts=AxisOpts( # grid_index=1, # is_scale=True, # split_number=2, axislabel_opts=LabelOpts(is_show=False), # axisline_opts=AxisLineOpts(is_show=False), axistick_opts=AxisTickOpts(is_show=False), # splitline_opts=SplitLineOpts(is_show=False), ), legend_opts=LegendOpts(pos_top='top', pos_left='55%', textstyle_opts=TextStyleOpts(font_size=30), orient='horizontal', legend_icon='rect'), )) return line
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
def draw_img(result): tmp = [(area, num * 5) for area, num in result] c = ( Geo(InitOpts(width="center", height="700px", page_title="Area-Top30", bg_color="#152353")) .add_schema( maptype="china", itemstyle_opts=options.ItemStyleOpts(color="#AFEEEE ", border_color="#111"), ) .add( "", tmp, type_=ChartType.EFFECT_SCATTER, color="red", ) .set_series_opts(label_opts=options.LabelOpts(is_show=False)) .set_global_opts(xaxis_opts=options.AxisOpts(), title_opts=options.TitleOpts(title="Area-Top30", pos_left="center", title_textstyle_opts=TextStyleOpts(color="#cdcd66", font_size=24, font_family="Courier New")),\ visualmap_opts=options.VisualMapOpts(min_=1700, max_=95000, range_text=("高", "低"), pos_left="10%", \ is_calculable=False, pos_top="top", range_color=["#DDDD00", "#C75D17", "#AA3434"],\ textstyle_opts=TextStyleOpts(color="white", font_family="Courier New"))) ) c.render()
def draw_chart(x_data, y_data, title, page_title, series_name, floder_name, res): bar = Bar( InitOpts(width="1500px", height="4600px", page_title=page_title, animation_opts=opts.AnimationOpts( animation_easing='exponentialInOut'))) bar.add_xaxis(xaxis_data=x_data) bar.add_yaxis(yaxis_data=y_data, series_name=series_name, category_gap="30%") bar.set_global_opts(title_opts=opts.TitleOpts(title=title + '粉丝数变化', subtitle=res[0] + '到' + res[1]), xaxis_opts=AxisOpts(boundary_gap=['5%', '10%']), toolbox_opts=opts.ToolboxOpts()) # bar.set_global_opts(xaxis_opts=AxisOpts(boundary_gap=['5%', '10%']), toolbox_opts=opts.ToolboxOpts()) bar.reversal_axis() bar.set_series_opts(label_opts=opts.LabelOpts(position="right")) bar.render("serve/chart/{0}/{1}.html".format(floder_name, title))
def plot(nodes: list, edges: list, **kw) -> None: width = kw.get("width", '98vw') height = kw.get("height", '95vh') repulsion = kw.get("repulsion", 2000) layout = kw.get("layout", "force") is_draggable = kw.get("is_draggable", True) output = kw.get("output", "SimplePlot.html") c = ( Graph(init_opts=InitOpts( width=width, height=height, page_title="SimplePlot", theme=ThemeType.MACARONS, )) .add("", nodes, edges, repulsion=repulsion, layout=layout, edge_length=100, is_draggable=is_draggable) .set_global_opts() .render(output) ) webbrowser.open(output)
def total_trend(day, shdeath, shcured, shsum, shpending) -> Line: line = ( Line(init_opts=InitOpts()).add_xaxis(day) # .add_yaxis("全国死亡",y_axis=death,is_connect_nones=True,is_smooth=True) .add_yaxis('死亡', shdeath, symbol_size=10, color='black', itemstyle_opts=ItemStyleOpts(color='black'), label_opts=LabelOpts(is_show=False), areastyle_opts=AreaStyleOpts(opacity=0.5, color='black'), stack=1, is_connect_nones=True, is_smooth=True).add_yaxis( '治愈', shcured, symbol_size=10, color='LimeGreen', itemstyle_opts=ItemStyleOpts(color='LimeGreen'), label_opts=LabelOpts(font_size=15, color='ForestGreen'), areastyle_opts=AreaStyleOpts(opacity=0.5, color='LimeGreen'), is_connect_nones=True, is_smooth=True). add_yaxis( '确诊', shsum, symbol_size=10, color='Orange', itemstyle_opts=ItemStyleOpts(color='Orange'), label_opts=LabelOpts(font_size=15, color='DarkOrange', font_weight='bold'), areastyle_opts=AreaStyleOpts(opacity=0.5, color='Orange'), stack=1, is_connect_nones=True, is_smooth=True).add_yaxis( '疑似', shpending, symbol_size=10, color='LightSkyBlue', itemstyle_opts=ItemStyleOpts(color='LightSkyBlue'), label_opts=LabelOpts(font_size=15, color='DarkBlue'), areastyle_opts=AreaStyleOpts(opacity=0.5, color='LightSkyBlue'), stack=1, is_connect_nones=True, is_smooth=True).set_global_opts( title_opts=TitleOpts( # title=title, # pos_left='10%', # pos_top='-10%', ), # tooltip_opts=TooltipOpts(formatter="{b} {a}\n {c}人"), datazoom_opts=[ DataZoomOpts( range_start=60, range_end=100, xaxis_index=[0, 1], ), DataZoomOpts(range_start=60, range_end=100, xaxis_index=[0, 1], type_='inside'), ], xaxis_opts=AxisOpts(name_gap=50), legend_opts=LegendOpts( pos_top='top', pos_left='10%', textstyle_opts=TextStyleOpts(font_size=30), orient='horizontal', legend_icon='rect'), tooltip_opts=TooltipOpts(textstyle_opts=TextStyleOpts( font_size=30)), graphic_opts=GraphicGroup( graphic_item=GraphicItem(left="12%", top="11%"), children=[ GraphicRect( graphic_item=GraphicItem(z=0, left="center", top="middle"), graphic_shape_opts=GraphicShapeOpts(width=150, height=90), graphic_basicstyle_opts=GraphicBasicStyleOpts( fill="#fff", stroke="black", line_width=3, )), GraphicText( graphic_item=GraphicItem(left="center", top="middle", z=0), graphic_textstyle_opts=GraphicTextStyleOpts( text= f"确诊{shsum[-1]}人\n\n疑似{shpending[-1]}人", font="bolder 20px sans-serif", graphic_basicstyle_opts= GraphicBasicStyleOpts(fill="#333"))) ]))) # line.overlap(bar) return line
for friend in friends: sex = friend["Sex"] if len(friend["RemarkName"]) > 0: mark_sex_counts[sex] += 1 else: no_mark_sex_counts[sex] += 1 print(no_mark_sex_counts, mark_sex_counts) # exit() from pyecharts.charts import Bar from pyecharts.options import TitleOpts, InitOpts, ToolboxOpts, AxisOpts bar = Bar( init_opts=InitOpts(page_title="撩课Python", width="1000px", height="600px")) bar.add_xaxis(sex_titles) bar.add_yaxis("有备注", mark_sex_counts, stack="1") bar.add_yaxis("无备注", no_mark_sex_counts, stack="1") bar.set_global_opts(title_opts=TitleOpts(title="撩课-Python-微信数据统计", subtitle="性别统计", title_link="https://www.itlike.com"), toolbox_opts=ToolboxOpts(), xaxis_opts=AxisOpts(name="性别"), yaxis_opts=AxisOpts(name="人数", max_=600)) # bar.add_yaxis("2组", [12, 6, 7]) # bar.render() bar.render("有无备注好友性别统计.html") # make_snapshot(snapshot, bar.render(), "sex_count.png")
for i in range(len(month_count)): for l in line_list: if len(l) == 6: if month_list[i] == l[-1]: month_count[i] += 1 elif len(l) == 7: if month_list[i] == l[-2:]: month_count[i] += 1 return month_count old_count_list = get_month_count_list(old_date_line, old_month_list) new_count_list = get_month_count_list(new_date_line, new_month_list) print(old_count_list) print(new_count_list) (Bar(init_opts=InitOpts( page_title="西元1298---5324年 平气 闰月分析", theme=ThemeType.LIGHT)).add_xaxis(old_month_list).add_yaxis( "该月份闰月次数", old_count_list).set_global_opts(title_opts=TitleOpts( title="西元1298---5324年 平气 闰月分析")).render("西元0002---1683年闰月分析.html")) (Bar(init_opts=InitOpts( page_title="西元1298---5324年 定气 闰月分析", theme=ThemeType.ESSOS)).add_xaxis(new_month_list).add_yaxis( "该月份闰月次数", new_count_list).set_global_opts(title_opts=TitleOpts( title="西元1298---5324年 定气 闰月分析")).render("西元1298---5324年闰月分析.html"))
if __name__ == "__main__": myAni = AnimationOpts( animation=True, # 开启动画 animation_threshold=2000, # 开启动画的阈值 animation_duration=1000, # 初始动画的时长 animation_easing="cubicOut", # 初始动画的缓动效果 animation_delay=0, # 初始动画的延迟 animation_duration_update=300, # 数据更新动画的时长 animation_easing_update="cubicOut", # 数据更新动画的缓动效果 animation_delay_update=300) # 数据更新动画的延迟 myOpts = InitOpts(width="1600px", height="800px", chart_id="myfirstchart", renderer=RenderType.CANVAS, page_title="firstchart", theme="white", bg_color=None, animation_opts=myAni) mysunburst = Sunburst(init_opts=myOpts) conn = sqlite3.connect('pdftables.sqlite') cur = conn.cursor() c = cur.execute("select * from company_info") companyinfo = c.fetchone() charttitle = companyinfo[1] units = companyinfo[2] c = cur.execute(
name_negative.append(name) name_negative = list(set(name_negative)) negative_content += '\n重要舆情新闻涉及到的股票为:\n' for name in name_negative: negative_content += (name + ',') f = open('data\\' + end_date[:10] + '舆情晨报新闻.txt', 'w', encoding='utf-8') # 保存文件 f.write(negative_content) f.close() print(negative_content) # 标签汇总 delete_words = [ '投资', '股票', '经济', '时政', '宏观经济', '时政外交', '财经', '金融', '公司', '国内宏观', '国外宏观', '国际社会', '分析师', '银行', '基金', '保险', '环比', '同比', '董事会', '股东', '外汇', '期货', '证券', '股权', '会议纪要', '子公司', '能源' ] # 去除无意义的词汇,相当于停用词 for w in delete_words: try: del words_score_dict[w] except KeyError: continue sorted_words_score = sorted(words_score_dict.items(), key=lambda d: d[1], reverse=True) print(sorted_words_score) words, scores = zip(*sorted_words_score) word_cloud = WordCloud(InitOpts(width="1600px", height="1000px")) scores = [math.sqrt(score) for score in scores] # 调整权重以画图显示的更好 words = list(zip(words, scores)) word_cloud.add("", words, shape="circle") word_cloud.render('data\\' + end_date[:10] + '舆情晨报词云.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 =============================" )
def wechat_signature_words(cls, friends): analysis = cls.toggle.analysis if not analysis.isAllEnabled: print( "================ analysis not allow signature word skip ==============" ) return all_word_list = [] final_words = {} for friend in friends: words = jieba.cut(friend["Signature"]) for w in list(words): res = re.match(r"([\u4e00-\u9fa5]+)", w) if res: all_word_list.append(w) # print(all_word_list) for w in all_word_list: if w not in final_words.keys(): final_words[w] = 0 final_words[w] += 1 sort_words = sorted(final_words.items(), key=lambda x: x[1], reverse=True) # print(sort_words) if analysis.pyechartsWordCloud: chart_wc = ( WordCloud(init_opts=InitOpts(page_title="微信签名词云")).add( "签名词云", sort_words, word_size_range=[20, 100], shape="triangle").set_global_opts( title_opts=TitleOpts(title="微信签名词云", pos_left="140px"), toolbox_opts=ToolboxOpts(is_show=True)) # .render("signature.html") ) try: make_snapshot(snapshot, chart_wc.render("signature.html"), "signature.png") except Exception as e: print("make snap shot error", e) else: chart_wc.render("chart_wc.html") if analysis.pilWordCloud: img = Image.open("IMG_7946.JPG") mask = np.array(img) wc = wordcloud.WordCloud( font_path="simsun.ttc", background_color="white", # stopwords=wordcloud.STOPWORDS.add("的"), stopwords={"在", "你", "的", "我", "不", "有", "了", "人"}, # max_words=100, mask=mask) wc.generate(" ".join(all_word_list)) wc.recolor(color_func=wordcloud.ImageColorGenerator(mask)) wc.to_file("word_cloud.png") print( "============================= Wchat signature words success =============================" )
def get_init_opts(): return InitOpts(theme=ThemeType.LIGHT, page_title='awesome zvt')
from zvt.domain import SecurityType from zvt.utils.time_utils import to_time_str r_hex = '#dc2624' # red, RGB = 220,38,36 dt_hex = '#2b4750' # dark teal, RGB = 43,71,80 tl_hex = '#45a0a2' # teal, RGB = 69,160,162 r1_hex = '#e87a59' # red, RGB = 232,122,89 tl1_hex = '#7dcaa9' # teal, RGB = 125,202,169 g_hex = '#649E7D' # green, RGB = 100,158,125 o_hex = '#dc8018' # orange, RGB = 220,128,24 tn_hex = '#C89F91' # tan, RGB = 200,159,145 g50_hex = '#6c6d6c' # grey-50, RGB = 108,109,108 bg_hex = '#4f6268' # blue grey, RGB = 79,98,104 g25_hex = '#c7cccf' # grey-25, RGB = 199,204,207 default_init_opts = InitOpts(theme="white", page_title='awesome zvt') def common_data(data_schema, security_id=None, codes=None, level=None, provider='eastmoney', columns=None, start_timestamp=None, end_timestamp=None, filters=None, session=None, order=None, limit=None): if security_id: df = get_data(data_schema=data_schema, security_id=security_id, codes=None, level=level, provider=provider, columns=columns, return_type='df', start_timestamp=start_timestamp, end_timestamp=end_timestamp, filters=filters, session=session, order=order, limit=limit) return [df] if codes: df_list = [] for code in codes: df_list.append( get_data(data_schema=data_schema, security_id=None, codes=[code], level=level, provider=provider, columns=columns, return_type='df', start_timestamp=start_timestamp,
def set_option(width, height): opt = InitOpts(width=width, height=height) return opt