def main(): dutPl0 = [] dutpl1 = [] maxCntPl0 = [] maxCntPl1 = [] page = Page("Cluster Padding Figure") txtFiles = [name for name in os.listdir('./') if name.endswith('.txt')] for textLogName in txtFiles: waferNum = re.split(r'_', textLogName) with open(textLogName, 'rt') as clusterFile: for line in clusterFile: if re.match(r'IncomingBBKCount[A-Za-z0-9_.\+\-\*\/\s]*BBKP', line): splitColon = re.split(r'\s*[:]\s*', line) splitColon1 = splitColon[0] splitColon2 = splitColon[1] splitColon3 = splitColon[2] listBlk = re.split(r'\s*[\s]\s*', splitColon3) padBlk = paddingBlk(listBlk) maxCnt = clusterBlk(padBlk) splitSpace = re.split(r'\s*[\s]\s*', splitColon1) intDut = int(splitSpace[1].replace('DUT', '')) if splitSpace[2] == "BBKP0": dutPl0.append(intDut) maxCntPl0.append(maxCnt) else: dutpl1.append(intDut) maxCntPl1.append(maxCnt) scatter = Scatter(waferNum[2]) scatter.add("PL0", dutPl0, maxCntPl0, xaxis_name = "DUT", yaxis_name = "Max Padding BB", is_more_utils = True) scatter.add("PL1", dutpl1, maxCntPl1, xaxis_name = "DUT", yaxis_name = "Max Padding BB", is_more_utils = True) page.add(scatter) page.render()
def draw_citys_pic(csv_file): page = Page(csv_file+":评论城市分析") info = count_city(csv_file) geo = Geo("","Ctipsy原创",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff") while True: # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计 try: attr, val = geo.cast(info) geo.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=6, symbol_size=15, is_visualmap=True) except ValueError as e: e = str(e) e = e.split("No coordinate is specified for ")[1] # 获取不支持的城市名称 info.pop(e) else: break info = sorted(info.items(), key=lambda x: x[1], reverse=False) # list排序 # print(info) info = dict(info) #list转dict # print(info) attr, val = [], [] for key in info: attr.append(key) val.append(info[key]) geo1 = Geo("", "评论城市分布", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") geo1.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True) #geo1.render(csv_file + "_城市dotmap.html") page.add_chart(geo1) geo2 = Geo("", "评论来源热力图",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff",) geo2.add("", attr, val, type="heatmap", is_visualmap=True, visual_range=[0, 50],visual_text_color='#fff', is_more_utils=True) #geo2.render(csv_file+"_城市heatmap.html") # 取CSV文件名的前8位数 page.add_chart(geo2) bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600 ) bar.add("", attr, val, is_visualmap=True, visual_range=[0, 100], visual_text_color='#fff',mark_point=["average"],mark_line=["average"], is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45) #bar.render(csv_file+"_城市评论bar.html") # 取CSV文件名的前8位数 page.add_chart(bar) pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600) pie.add("", attr, val, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') #pie.render(csv_file + "_城市评论Pie.html") # 取CSV文件名的前8位数 page.add_chart(pie) page.render(csv_file + "_城市评论分析汇总.html")
def plotFoodRanging(list_y1, list_y2, list_y3, list_y4, list_y5, list_y6, list_y7, list_y8, list_y9, list_y10, list_y11, list_y12): page = Page() line1 = Line("上海饭店评分统计", "数据来源于大众点评TOP100", width=1200) line1.add("口味", list_y1[0], list_y1[1], mark_point=["max", "min"]) line1.add("环境", list_y1[0], list_y1[2], mark_point=["max", "min"]) line1.add("服务", list_y1[0], list_y1[3], mark_point=["max", "min"]) line1.add("综合", list_y1[0], list_y1[4], mark_point=["max", "min"]) bar1 = Bar("上海饭店评分统计", "数据来源于大众点评TOP100") bar1.add("上海", list_y1[0][:10], list_y1[4][:10], mark_point=["max", "min"]) wordcloud1 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud1.add("", list_y1[0][:20], list_y1[4][:20], word_size_range=[20, 100]) line2 = Line("北京饭店评分统计", "数据来源于大众点评TOP100", width=1200) line2.add("口味", list_y2[0], list_y2[1], mark_point=["max", "min"]) line2.add("环境", list_y2[0], list_y2[2], mark_point=["max", "min"]) line2.add("服务", list_y2[0], list_y2[3], mark_point=["max", "min"]) line2.add("综合", list_y2[0], list_y2[4], mark_point=["max", "min"]) bar2 = Bar("北京饭店评分统计", "数据来源于大众点评TOP100") bar2.add("北京", list_y2[0][:10], list_y2[4][:10], mark_point=["max", "min"]) wordcloud2 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud2.add("", list_y2[0][:20], list_y2[4][:20], word_size_range=[20, 100]) line3 = Line("广州饭店评分统计", "数据来源于大众点评TOP100", width=1200) line3.add("口味", list_y3[0], list_y3[1], mark_point=["max", "min"]) line3.add("环境", list_y3[0], list_y3[2], mark_point=["max", "min"]) line3.add("服务", list_y3[0], list_y3[3], mark_point=["max", "min"]) line3.add("综合", list_y3[0], list_y3[4], mark_point=["max", "min"]) bar3 = Bar("广州饭店评分统计", "数据来源于大众点评TOP100") bar3.add("广州", list_y3[0][:10], list_y3[4][:10], mark_point=["max", "min"]) wordcloud3 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud3.add("", list_y3[0][:20], list_y3[4][:20], word_size_range=[20, 100]) line4 = Line("深圳饭店评分统计", "数据来源于大众点评TOP100", width=1200) line4.add("口味", list_y4[0], list_y4[1], mark_point=["max", "min"]) line4.add("环境", list_y4[0], list_y4[2], mark_point=["max", "min"]) line4.add("服务", list_y4[0], list_y4[3], mark_point=["max", "min"]) line4.add("综合", list_y4[0], list_y4[4], mark_point=["max", "min"]) bar4 = Bar("深圳饭店评分统计", "数据来源于大众点评TOP100") bar4.add("深圳", list_y4[0][:10], list_y4[4][:10], mark_point=["max", "min"]) wordcloud4 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud4.add("", list_y4[0][:20], list_y4[4][:20], word_size_range=[20, 100]) line5 = Line("天津饭店评分统计", "数据来源于大众点评TOP100", width=1200) line5.add("口味", list_y5[0], list_y5[1], mark_point=["max", "min"]) line5.add("环境", list_y5[0], list_y5[2], mark_point=["max", "min"]) line5.add("服务", list_y5[0], list_y5[3], mark_point=["max", "min"]) bar5 = Bar("天津饭店评分统计", "数据来源于大众点评TOP100") bar5.add("天津", list_y5[0][:10], list_y5[4][:10], mark_point=["max", "min"]) wordcloud5 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud5.add("", list_y5[0][:20], list_y5[4][:20], word_size_range=[20, 100]) line6 = Line("杭州饭店评分统计", "数据来源于大众点评TOP100", width=1200) line6.add("口味", list_y6[0], list_y6[1], mark_point=["max", "min"]) line6.add("环境", list_y6[0], list_y6[2], mark_point=["max", "min"]) line6.add("服务", list_y6[0], list_y6[3], mark_point=["max", "min"]) line6.add("综合", list_y6[0], list_y6[4], mark_point=["max", "min"]) bar6 = Bar("杭州饭店评分统计", "数据来源于大众点评TOP100") bar6.add("杭州", list_y6[0][:10], list_y6[4][:10], mark_point=["max", "min"]) wordcloud6 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud6.add("", list_y6[0][:20], list_y6[4][:20], word_size_range=[20, 100]) line7 = Line("南京饭店评分统计", "数据来源于大众点评TOP100", width=1200) line7.add("口味", list_y7[0], list_y7[1], mark_point=["max", "min"]) line7.add("环境", list_y7[0], list_y7[2], mark_point=["max", "min"]) line7.add("服务", list_y7[0], list_y7[3], mark_point=["max", "min"]) line7.add("综合", list_y7[0], list_y7[4], mark_point=["max", "min"]) bar7 = Bar("南京饭店评分统计", "数据来源于大众点评TOP100") bar7.add("南京", list_y7[0][:10], list_y7[4][:10], mark_point=["max", "min"]) wordcloud7 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud7.add("", list_y7[0][:20], list_y7[4][:20], word_size_range=[20, 100]) line8 = Line("苏州饭店评分统计", "数据来源于大众点评TOP100", width=1200) line8.add("口味", list_y8[0], list_y8[1], mark_point=["max", "min"]) line8.add("环境", list_y8[0], list_y8[2], mark_point=["max", "min"]) line8.add("服务", list_y8[0], list_y8[3], mark_point=["max", "min"]) line8.add("综合", list_y8[0], list_y8[4], mark_point=["max", "min"]) bar8 = Bar("苏州饭店评分统计", "数据来源于大众点评TOP100") bar8.add("苏州", list_y8[0][:10], list_y8[4][:10], mark_point=["max", "min"]) wordcloud8 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud8.add("", list_y8[0][:20], list_y8[4][:20], word_size_range=[20, 100]) line9 = Line("成都饭店评分统计", "数据来源于大众点评TOP100", width=1200) line9.add("口味", list_y9[0], list_y9[1], mark_point=["max", "min"]) line9.add("环境", list_y9[0], list_y9[2], mark_point=["max", "min"]) line9.add("服务", list_y9[0], list_y9[3], mark_point=["max", "min"]) line9.add("综合", list_y9[0], list_y9[4], mark_point=["max", "min"]) bar9 = Bar("成都饭店评分统计", "数据来源于大众点评TOP100") bar9.add("成都", list_y9[0][:10], list_y9[4][:10], mark_point=["max", "min"]) wordcloud9 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud9.add("", list_y9[0][:20], list_y9[4][:20], word_size_range=[20, 100]) line10 = Line("武汉饭店评分统计", "数据来源于大众点评TOP100", width=1200) line10.add("口味", list_y10[0], list_y10[1], mark_point=["max", "min"]) line10.add("环境", list_y10[0], list_y10[2], mark_point=["max", "min"]) line10.add("服务", list_y10[0], list_y10[3], mark_point=["max", "min"]) line10.add("综合", list_y10[0], list_y10[4], mark_point=["max", "min"]) bar10 = Bar("武汉饭店评分统计", "数据来源于大众点评TOP100") bar10.add("武汉", list_y10[0][:10], list_y10[4][:10], mark_point=["max", "min"]) wordcloud10 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud10.add("", list_y10[0][:20], list_y10[4][:20], word_size_range=[20, 100]) line11 = Line("重庆饭店评分统计", "数据来源于大众点评TOP100", width=1200) line11.add("口味", list_y11[0], list_y11[1], mark_point=["max", "min"]) line11.add("环境", list_y11[0], list_y11[2], mark_point=["max", "min"]) line11.add("服务", list_y11[0], list_y11[3], mark_point=["max", "min"]) line11.add("综合", list_y11[0], list_y11[4], mark_point=["max", "min"]) bar11 = Bar("重庆饭店评分统计", "数据来源于大众点评TOP100") bar11.add("重庆", list_y11[0][:10], list_y11[4][:10], mark_point=["max", "min"]) wordcloud11 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud11.add("", list_y11[0][:20], list_y11[4][:20], word_size_range=[20, 100]) line12 = Line("西安饭店评分统计", "数据来源于大众点评TOP100", width=1200) line12.add("口味", list_y12[0], list_y12[1], mark_point=["max", "min"]) line12.add("环境", list_y12[0], list_y12[2], mark_point=["max", "min"]) line12.add("服务", list_y12[0], list_y12[3], mark_point=["max", "min"]) line12.add("综合", list_y12[0], list_y12[4], mark_point=["max", "min"]) bar12 = Bar("西安饭店评分统计", "数据来源于大众点评TOP100") bar12.add("西安", list_y12[0][:10], list_y12[4][:10], mark_point=["max", "min"]) wordcloud12 = WordCloud(width=1000, height=620, background_color="#EECFA1") wordcloud12.add("", list_y12[0][:20], list_y12[4][:20], word_size_range=[20, 100]) page.add(line1) page.add(wordcloud1) page.add(bar1) page.add(line2) page.add(wordcloud2) page.add(bar2) page.add(line3) page.add(wordcloud3) page.add(bar3) page.add(line4) page.add(wordcloud4) page.add(bar4) page.add(line5) page.add(wordcloud5) page.add(bar5) page.add(line6) page.add(wordcloud6) page.add(bar6) page.add(line7) page.add(wordcloud7) page.add(bar7) page.add(line8) page.add(wordcloud8) page.add(bar8) page.add(line9) page.add(wordcloud9) page.add(bar9) page.add(line10) page.add(wordcloud10) page.add(bar10) page.add(line11) page.add(wordcloud11) page.add(bar11) page.add(line12) page.add(wordcloud12) page.add(bar12) data1 = pd.DataFrame(list_y1[4][:10], list_y1[0][:10], ["综合值"]) print(data1) data2 = pd.DataFrame(list_y2[4][:10], list_y2[0][:10], ["综合值"]) print(data2) data3 = pd.DataFrame(list_y3[4][:10], list_y3[0][:10], ["综合值"]) print(data3) data4 = pd.DataFrame(list_y4[4][:10], list_y4[0][:10], ["综合值"]) print(data4) data5 = pd.DataFrame(list_y5[4][:10], list_y5[0][:10], ["综合值"]) print(data5) data6 = pd.DataFrame(list_y6[4][:10], list_y6[0][:10], ["综合值"]) print(data6) data7 = pd.DataFrame(list_y7[4][:10], list_y7[0][:10], ["综合值"]) print(data7) data8 = pd.DataFrame(list_y8[4][:10], list_y8[0][:10], ["综合值"]) print(data8) data9 = pd.DataFrame(list_y9[4][:10], list_y9[0][:10], ["综合值"]) print(data9) data10 = pd.DataFrame(list_y10[4][:10], list_y10[0][:10], ["综合值"]) print(data10) data11 = pd.DataFrame(list_y11[4][:10], list_y11[0][:10], ["综合值"]) print(data11) data12 = pd.DataFrame(list_y12[4][:10], list_y12[0][:10], ["综合值"]) print(data12) page.render("全部.html")
for i in range(len(s)): len1 = len(self.getlongestpalindrome(s, i, i)) if len1 > len(palindrome): palindrome = self.getlongestpalindrome(s, i, i) #回文字符串中间字符仅有一个 len2 = len(self.getlongestpalindrome(s, i, i + 1)) if len2 > len(palindrome): palindrome = self.getlongestpalindrome(s, i, i + 1) return True if len(palindrome) > 5 else False a = Solution() a.longestPalindrome('alfrederfl') all_name = data['Name'].unique() palindrome_name = [] for name in all_name: if a.longestPalindrome(name): palindrome_name.append(name) palindrome_data = data[data['Name'].isin(palindrome_name)].groupby('Name').Count.sum() name3 = list(palindrome_data.index) value3 = list(palindrome_data.values) wordcloud5 = WordCloud("带回文的名字",width=1000, height=600,background_color='#feeeed') # feeeed wordcloud5.add("", name3, value3, word_size_range=[20, 100],shape='diamond') #wordcloud5.render() page.add(wordcloud5) page.render("./totalpicture.html")
def score_draw(csv_file): page = Page(csv_file + ":评论等级分析") score, date, val, score_list = [], [], [], [] result = {} path = os.path.abspath(os.curdir) csv_file = path + "\\" + csv_file + ".csv" csv_file = csv_file.replace('\\', '\\\\') d = pd.read_csv(csv_file, engine='python', encoding='utf-8')[[ 'score', 'date' ]].dropna() # 读取CSV转为dataframe格式,并丢弃评论为空的记录 for indexs in d.index: # 一种遍历df行的方法(下面还有第二种,iterrows) score_list.append(tuple( d.loc[indexs].values[:])) # 目前只找到转换为tuple然后统计相同元素个数的方法 # print("有效评分总数量为:",len(score_list), " 条") for i in set(list(score_list)): result[i] = score_list.count(i) # dict类型 ('很差', '2018-04-28'): 55 info = [] for key in result: score = key[0] date = key[1] val = result[key] info.append([score, date, val]) info_new = DataFrame(info) # 将字典转换成为数据框 info_new.columns = ['score', 'date', 'votes'] info_new.sort_values('date', inplace=True) # 按日期升序排列df,便于找最早date和最晚data,方便后面插值 # print("first df", info_new) # 以下代码用于插入空缺的数据,每个日期的评分类型应该有5中,依次遍历判断是否存在,若不存在则往新的df中插入新数值 mark = 0 creat_df = pd.DataFrame(columns=['score', 'date', 'votes']) # 创建空的dataframe for i in list(info_new['date']): location = info_new[(info_new.date == i) & (info_new.score == "力荐")].index.tolist() if location == []: creat_df.loc[mark] = ["力荐", i, 0] mark += 1 location = info_new[(info_new.date == i) & (info_new.score == "推荐")].index.tolist() if location == []: creat_df.loc[mark] = ["推荐", i, 0] mark += 1 location = info_new[(info_new.date == i) & (info_new.score == "还行")].index.tolist() if location == []: creat_df.loc[mark] = ["还行", i, 0] mark += 1 location = info_new[(info_new.date == i) & (info_new.score == "较差")].index.tolist() if location == []: creat_df.loc[mark] = ["较差", i, 0] mark += 1 location = info_new[(info_new.date == i) & (info_new.score == "很差")].index.tolist() if location == []: creat_df.loc[mark] = ["很差", i, 0] mark += 1 info_new = info_new.append(creat_df.drop_duplicates(), ignore_index=True) score_list = [] info_new.sort_values('date', inplace=True) # 按日期升序排列df,便于找最早date和最晚data,方便后面插值 # print(info_new) for index, row in info_new.iterrows(): # 第二种遍历df的方法 score_list.append([row['date'], row['votes'], row['score']]) tr = ThemeRiver() tr.add(['力荐', '推荐', '还行', '较差', '很差'], score_list, is_label_show=True, is_more_utils=True) page.add_chart(tr) attr, v1, v2, v3, v4, v5 = [], [], [], [], [], [] attr = list(sorted(set(info_new['date']))) bar = Bar() for i in attr: v1.append( int(info_new[(info_new['date'] == i) & (info_new['score'] == "力荐")]['votes'])) v2.append( int(info_new[(info_new['date'] == i) & (info_new['score'] == "推荐")]['votes'])) v3.append( int(info_new[(info_new['date'] == i) & (info_new['score'] == "还行")]['votes'])) v4.append( int(info_new[(info_new['date'] == i) & (info_new['score'] == "较差")]['votes'])) v5.append( int(info_new[(info_new['date'] == i) & (info_new['score'] == "很差")]['votes'])) bar.add("力荐", attr, v1, is_stack=True) bar.add("推荐", attr, v2, is_stack=True) bar.add("还行", attr, v3, is_stack=True) bar.add("较差", attr, v4, is_stack=True) bar.add("很差", attr, v5, is_stack=True, is_convert=True, mark_line=["average"], is_more_utils=True) page.add_chart(bar) line = Line() line.add("力荐", attr, v1, is_stack=True) line.add("推荐", attr, v2, is_stack=True) line.add("还行", attr, v3, is_stack=True) line.add("较差", attr, v4, is_stack=True) line.add("很差", attr, v5, is_stack=True, is_convert=False, mark_line=["average"], is_more_utils=True) page.add_chart(line) page.render(csv_file[:-4] + "_日投票量分析汇总.html")
def xianxinghuigui(): huigui_f = pd.read_excel(path1) print(huigui_f.head()) Indv = huigui_f['状态打分'] Depv = huigui_f['客户成绩'] Indv=sm.add_constant(Indv) huigui=sm.OLS(Depv,Indv) huigui=huigui.fit() EEE = str(huigui.summary()) print(huigui.summary()) print(EEE) space = 5 # # PIL模块中,确定写入到图片中的文本字体 # font = ImageFont.truetype('Arial.ttf', 15, encoding='utf-8') # # Image模块创建一个图片对象 # im = Image.new('RGB',(800, 600),(255,255,255,255)) # # ImageDraw向图片中进行操作,写入文字或者插入线条都可以 # draw = ImageDraw.Draw(im) # draw.text((50,10),text = EEE,font=font, fill=(0,0,0)) # im.show() # im.save('12345.PNG', "PNG") # PIL模块中,确定写入到图片中的文本字体 font = ImageFont.truetype('hyqh.ttf', 18, encoding='utf-8') # Image模块创建一个图片对象 im = Image.new('RGB',(10, 10),(255,255,255,255)) # ImageDraw向图片中进行操作,写入文字或者插入线条都可以 draw = ImageDraw.Draw(im, "RGB") # 根据插入图片中的文字内容和字体信息,来确定图片的最终大小 img_size = draw.multiline_textsize(EEE, font=font) # 图片初始化的大小为10-10,现在根据图片内容要重新设置图片的大小 im_new = im.resize((img_size[0]+space*2, img_size[1]+space*2)) del draw del im draw = ImageDraw.Draw(im_new, 'RGB') # 批量写入到图片中,这里的multiline_text会自动识别换行符 draw.multiline_text((space,space), text = EEE, fill=(0,0,0), font=font) im_new.save('OLS.png', "png") page1 =Page(page_title='OLS') sc = Scatter('OLS Regression Result',width = 800,height = 600) sc_v1, sc_v2 = sc.draw("OLS.png") sc.add("summary", sc_v1, sc_v2, label_color=["#000"],symbol_size = 1, is_xaxis_show = False,is_yaxis_show = False,is_legend_show = 0) page1.add(sc) Indv_prime = np.linspace(Indv['状态打分'].min(),Indv['状态打分'].max(),100)[:,np.newaxis] BBB = [] for BB in Indv_prime.tolist(): BB = round(BB[0],2) BBB.append(BB) #print(BBB) Indv_prime=sm.add_constant(Indv_prime) Depv_hat=huigui.predict(Indv_prime) CCC = Depv_hat.tolist() line1 = Line('Linear regression curve') line1.add('',BBB,CCC,xaxis_name = '状态打分', yaxis_name = '客户预测值', yaxis_interval=20) page1.add(line1) page1.render('线性回归分析结果报告.html')
bar_3 = Bar("2014 年销量", "数据纯属虚构") bar_3.add("春季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_3.add("夏季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_3.add("秋季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_3.add("冬季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_4 = Bar("2015 年销量", "数据纯属虚构") bar_4.add("春季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_4.add("夏季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_4.add("秋季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_4.add("冬季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_5 = Bar("2016 年销量", "数据纯属虚构") bar_5.add("春季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_5.add("夏季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_5.add("秋季", attr, [np.random.randint(10, 100) for _ in range(6)]) bar_5.add("冬季", attr, [np.random.randint(10, 300) for _ in range(6)], is_legend_show=True) bar_1.use_theme("Mywalden") bar_5.use_theme("dark") timeline = Timeline(is_auto_play=True, timeline_bottom=0) page.add(bar_1) page.add(bar_2) page.add(bar_3) page.add(bar_4) page.add(bar_5) page.render()
page = Page() # step 1 # bar attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) page.add(bar) # step 2 # scatter3D import random data = [[ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100) ] for _ in range(80)] range_color = [ '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026' ] scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) page.add(scatter3D) # step 2 # page.render() # step 3 page.render(path="./data/07-07按顺序展示多个图.html")
class Draw(object): def __init__(self): self.page = Page() self.style = Style(width=1100, height=600) self.yesterday = datetime.date.today() + datetime.timedelta(-1) def one_pic(self): """ 新品与下架数据示例 """ new_app_list = list() download_app_list = list() app_genre_info = MySQL().select( "select genre from zen_master where offline_date='{}' and (save_type='{}' or save_type='{}')" .format(self.yesterday, '新品', '下架')) app_genre_list = list(set(info['genre'] for info in app_genre_info)) for genre in app_genre_list: new_app_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and genre='{}' and save_type='{}'" .format(self.yesterday, genre, '新品'))) download_app_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and genre='{}' and save_type='{}'" .format(self.yesterday, genre, '下架'))) bar = Bar('新品与下架数据示例', **self.style.init_style) bar.add('新品发现', app_genre_list, [info[0]['count(*)'] for info in new_app_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) bar.add('下架监控', app_genre_list, [info[0]['count(*)'] for info in download_app_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) self.page.add(bar) def two_pic(self): """ 新品发现、下架监控近30天示例 """ data_list = list() new_app_total_list = list() download_app_total_list = list() begin = datetime.date(2019, 7, 21) end = datetime.date(2019, 8, 22) d = begin delta = datetime.timedelta(days=1) while d <= end: data_list.append(d.strftime("%Y-%m-%d")) d += delta for data in data_list: new_app_total_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and save_type='{}'" .format(data, '新品'))) download_app_total_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and save_type='{}'" .format(data, '下架'))) bar2 = Bar('新品发现、下架监控近30天示例', **self.style.init_style) bar2.add('新品发现', data_list, [info[0]['count(*)'] for info in new_app_total_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) bar2.add('下架监控', data_list, [info[0]['count(*)'] for info in download_app_total_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) self.page.add(bar2) def three_pic(self): """ 清词与清榜数据示例 """ word_list = list() top_list = list() app_genre_info = MySQL().select( "select genre from zen_master where offline_date='{}' and (save_type='{}' or save_type='{}')" .format(self.yesterday, '清词', '清榜')) app_genre_list = list(set(info['genre'] for info in app_genre_info)) for genre in app_genre_list: word_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and genre='{}' and save_type='{}'" .format(self.yesterday, genre, '清词'))) top_list.append(MySQL().select( "select count(*) from zen_master where offline_date='{}' and genre='{}' and save_type='{}'" .format(self.yesterday, genre, '清榜'))) bar3 = Bar('清词与清榜数据示例', **self.style.init_style) bar3.add('清词应用', app_genre_list, [info[0]['count(*)'] for info in word_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) bar3.add('清榜应用', app_genre_list, [info[0]['count(*)'] for info in top_list], is_stack=False, is_more_utils=True, xaxis_interval=0, xaxis_rotate=30, yaxis_rotate=30, is_label_show=True) self.page.add(bar3) def creation(self): """ 开始画图,并修改文件 """ self.one_pic() self.two_pic() self.three_pic() self.page.render('./html/{}.html'.format(self.yesterday)) download_app_info = [( x['app_name'], x['offline_rank'], x['trackId'] ) for x in MySQL().select( "select app_name, offline_rank, trackId from zen_master where offline_rank <= %d and save_type='%s' and offline_rank != %d and offline_date='%s'" % (150, '下架', 0, self.yesterday))] html_str = '' for index, info in enumerate(download_app_info): html_str += """ <tr> <td>{}</td> <td>{}</td> <td>{}</td> <td>{}</td> </tr> """.format(index + 1, info[0], info[2], info[1]) clear_app_info = [(x['app_name'], x['offline_rank']) for x in MySQL( ).select( "select app_name, offline_rank from zen_master where offline_rank <= %d and save_type='%s' and offline_rank != %d and offline_date='%s'" % (150, '清榜', 0, self.yesterday))] if len(clear_app_info) == 0: clear_app_info = [('无', '无')] html2_str = "" for index2, info2 in enumerate(clear_app_info): html2_str += """ <tr> <td>{}</td> <td>{}</td> <td>{}</td> </tr> """.format(index2 + 1, info2[0], info2[1]) num_result_list = list() for price_type in ['免费', '付费']: for save_type in ['新品', '下架', '清词', '清榜']: info = MySQL().select( "select count(*) from zen_master where offline_date='{}' and save_type='{}' and price_type='{}'" .format(self.yesterday, save_type, price_type)) for x in info: number = x['count(*)'] num_result_list.append((save_type, price_type, number)) html3_str = '' result = list() for index1, x in enumerate(num_result_list[:len(num_result_list) // 2]): for index2, y in enumerate(num_result_list[len(num_result_list) // 2:]): if index1 == index2: result.append([x[0], y[2], x[2]]) html3_str += """ <tr> <td>{}</td> <td>{}</td> <td>{}</td> </tr> """.format(x[0], y[2], x[2]) num_result_list2 = list() for price_type in ['免费', '付费']: for save_type in ['新品', '下架', '清词', '清榜']: info = MySQL().select( "select count(*) from zen_master where offline_date='{}' and save_type='{}' and price_type='{}'" .format(datetime.date.today() + datetime.timedelta(-2), save_type, price_type)) for x in info: number = x['count(*)'] num_result_list2.append((save_type, price_type, number)) html4_str = '' for index1, x in enumerate(num_result_list2[:len(num_result_list2) // 2]): for index2, y in enumerate( num_result_list2[len(num_result_list2) // 2:]): if index1 == index2: html4_str += """ <tr> <td>{}</td> <td>{}</td> </tr> """.format(y[2], x[2]) file = open("./html/{}.html".format(self.yesterday), 'r', encoding='utf8') content = file.read() keyword = '</head>' post = content.find(keyword) if post != -1: content = content[:post + len(keyword)] + """ <h1>各类型产品收费类型数据</h1> <table border="1" style="float:left; width:300px;"> <tr> <td rowspan="1" width="72">产品类别</td> <td rowspan="1">付费(昨天)</td> <td rowspan="1">免费(昨天)</td> </tr> {2} </table> <table border="1" style="float:left; width:300px;";> <tr> <td rowspan="1">付费(前天)</td> <td rowspan="1">免费(前天)</td> </tr> {3} </table> <div style="float:left"> <table> <h1>下架产品近期最高排名150名以内</h1> <tbody> <tr> <td rowspan="1" width="72">序号</td> <td rowspan="1">App名称</td> <td rowspan="1" width="72">AppID</td> <td rowspan="1">排名</td> </tr> {0} </tbody> </table> <table> </div> <h1>清榜产品前排名150名以内</h1> <tbody> <tr> <td rowspan="1" width="72">序号</td> <td rowspan="1">App名称</td> <td rowspan="1">排名</td> </tr> {1} </tbody> </table> """.format(html_str, html2_str, html3_str, html4_str) + content[post + len(keyword):] file = open("./html/{}.html".format(self.yesterday), 'w', encoding='utf8') file.write(content) file.close()
def graphpage(items,startdate,enddate,option,width1, height1): #labels:复权ork线or分笔 option:hfq, qfq or 15, 30, D, etc page = Page() for i in items:#generate numbers of graphs according to numbers of queries in treewidget j = re.split("-",i) if len(j)==3: a = generateline(j[1],j[2],startdate,enddate,option)#stock number, Type, startdate, enddate, 30 or 15 or days if a is None: continue time = [d[0] for d in a]#get time from returned dictionary if j[2]!="Kline": if len(a[0])==4 and a[0][2]=="bar": #for 分笔data overlap = Overlap() form = [e[1] for e in a] bar = Bar(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(j[0] + "-" + j[2], time, form, yaxis_min = "dataMin",yaxis_max = "dataMax",is_datazoom_show = True, datazoom_type = "slider") overlap.add(bar) line = Line(j[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in a] line.add(j[0] + "price", time, price, yaxis_min = "dataMin",yaxis_max = "dataMax", is_datazoom_show = True, datazoom_type = "slider", yaxis_type="value") overlap.add(line,yaxis_index=1, is_add_yaxis=True) page.add(overlap) if len(a[0])==5 and a[0][3]=="pie": overlap = Overlap() timeline = Timeline(is_auto_play=False, timeline_bottom=0) #zip(namearray,valuearray,quarter,flag,num) namearray = [c[0] for c in a] valuearray = [d[1] for d in a] quarter = [e[2] for e in a] num = a[0][4] for x in range(0, num / 10): list1 = valuearray[x] names = namearray[x] quarters = quarter[x][0] for idx, val in enumerate(list1): list1[idx] = float(val) pie = Pie(j[0]+"-"+"前十股东".decode("utf-8"),width=width1 * 10 / 11, height=(height1 * 10 / 11)) pie.add(j[0]+"-"+"前十股东".decode("utf-8"), names, list1, radius=[30, 55], is_legend_show=False, is_label_show=True, label_formatter = "{b}: {c}\n{d}%") # print list # print names # print quarterarray timeline.add(pie, quarters) # namearray = [y for y in namearray[x]] timeline.render() return #need more statement else: form = [e[1] for e in a]#for not分笔 data line = Line(j[0] + "-" + j[2], width=width1*10/11, height=(height1*10/11)/len(items)) line.add(j[0] + "-" + j[2], time, form, is_datazoom_show=True, datazoom_type="slider",yaxis_min="dataMin",yaxis_max="dataMax") page.add(line) else: overlap = Overlap()#for k线 close = zip(*a)[2] candle = [[x[1], x[2], x[3], x[4]] for x in a] candlestick = Kline(j[0] + "-" + j[2], width=width1*10/11, height = (height1*10/11) / len(items)) candlestick.add(j[0], time, candle, is_datazoom_show=True, datazoom_type="slider",yaxis_interval = 1) overlap.add(candlestick) if len(close)>10: ma10 = calculateMa(close, 10) line1 = Line(title_color="#C0C0C0") line1.add(j[0] + "-" + "MA10", time, ma10) overlap.add(line1) if len(close)>20: ma20 = calculateMa(close, 20) line2 = Line(title_color="#C0C0C0") line2.add(j[0] + "-" + "MA20", time, ma20) overlap.add(line2) if len(close)>30: ma30 = calculateMa(close, 30) line3 = Line(title_color="#C0C0C0") line3.add(j[0] + "-" + "MA30", time, ma30) overlap.add(line3) page.add(overlap) else: for k in range(1, len(j)/3):#if graphs are combined j[3*k-1] = re.sub("\n&","",j[3*k-1]) sizearray=[] #if j[1] != "Candlestick" layout = Overlap() for i in xrange(0, len(j),3): array = j[i:i +3] b = generateline(array[1],array[2],startdate,enddate,option) if b is None: continue btime = [d[0] for d in b] if array[2] != "Kline": if len(b[0])==4 and b[0][2]=="bar": form = [e[1] for e in b] bar = Bar(array[0] + "-" + array[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(array[0] + "-" + array[2], btime, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax") layout.add(bar) line = Line(array[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in b] line.add(array[0] + "price", btime, price, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_type="value") layout.add(line, yaxis_index=1, is_add_yaxis=True) else: line = Line(array[0] + "-" + array[2],width=width1*10/11, height=(height1*10/11) / len(items)) line.add(array[0]+"-"+array[2], btime, b, is_datazoom_show=True, yaxis_max = "dataMax", yaxis_min = "dataMin",datazoom_type="slider") layout.add(line) else: candle = [[x[1], x[2], x[3], x[4]] for x in b] candlestick = Kline(array[0] + "-" + array[1], width=width1*10/11, height=(height1*10/11) / len(items)) candlestick.add(array[0], btime, candle, is_datazoom_show=True, datazoom_type=["slider"]) #if i == 0: close = zip(*b)[2] if len(close)>10: ma10 = calculateMa(close, 10) line4 = Line(title_color="#C0C0C0") line4.add(array[0] + "-" + "MA10", btime, ma10) layout.add(line4) if len(close)>20: ma20 = calculateMa(close, 20) line5 = Line(title_color="#C0C0C0") line5.add(array[0] + "-" + "MA20", btime, ma20) layout.add(line5) if len(close)>30: ma30 = calculateMa(close, 30) line6 = Line(title_color="#C0C0C0") line6.add(array[0] + "-" + "MA30", btime, ma30) layout.add(line6) layout.add(candlestick) page.add(layout) page.render()
Page.add(bar1) bar2=Bar("2019年12月调查点同比收支情况",width=1600,height=800) bar2.add('201912收入',data1['调查小区'].tolist(),data1['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"], is_label_show=True) bar2.add('201912支出',data1['调查小区'].tolist(),data1['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"], is_label_show=True) bar2.add('201812收入',data4['调查小区'].tolist(),data4['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"], is_label_show=True) bar2.add('201812支出',data4['调查小区'].tolist(),data4['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True,xaxis_interval=0,xaxis_rotate=90, is_label_show=True, is_datazoom_show=True,datazoom_type='inside') Page.add(bar2) bar3=Bar("2020年1月调查点同比记账条数",width=1600,height=800) bar3.add('2020201记账条数',data2['调查小区'].tolist(),data2['记账条数'].tolist(), mark_point=['max','min'],mark_line=["average"],is_more_utils=True,xaxis_interval=0,xaxis_rotate=90, is_label_show=True) bar3.add('201901记账条数',data5['调查小区'].tolist(),data5['记账条数'].tolist(), mark_point=['max','min'],mark_line=["average"],is_more_utils=True,xaxis_interval=0,xaxis_rotate=90, is_label_show=True, is_datazoom_show=True,datazoom_type='inside') Page.add(bar3) bar4=Bar("2020年1月调查点同比收支情况",width=1600,height=800) bar4.add('202001收入',data2['调查小区'].tolist(),data2['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar4.add('202001支出',data2['调查小区'].tolist(),data2['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar4.add('201901收入',data5['调查小区'].tolist(),data5['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar4.add('201901支出',data5['调查小区'].tolist(),data5['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True,xaxis_interval=0,xaxis_rotate=90, is_label_show=True, is_datazoom_show=True,datazoom_type='inside') Page.add(bar4) bar5=Bar("2020年2月调查点同比记账条数",width=1600,height=800) bar5.add('202002记账条数',data3['调查小区'].tolist(),data3['记账条数'].tolist(), mark_point=['max','min'],mark_line=["average"], is_label_show=True) bar5.add('201902记账条数',data6['调查小区'].tolist(),data6['记账条数'].tolist(), mark_point=['max','min'],mark_line=["average"],is_more_utils=True,xaxis_interval=0,xaxis_rotate=90, is_label_show=True, is_datazoom_show=True,datazoom_type='inside') Page.add(bar5) bar6=Bar("2020年2月调查点同比收支情况",width=1600,height=800) bar6.add('202002收入',data3['调查小区'].tolist(),data3['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar6.add('202002支出',data3['调查小区'].tolist(),data3['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar6.add('201902收入',data6['调查小区'].tolist(),data6['收入合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True, is_label_show=True) bar6.add('201902支出',data6['调查小区'].tolist(),data6['支出合计'].astype(int).tolist(), mark_point=['max','min'],mark_line=["average"],is_more_units=True,xaxis_interval=0,xaxis_rotate=90, is_datazoom_show=True,datazoom_type='inside', is_label_show=True) Page.add(bar6) Page.render()
def calc_bfaf20(ct_cmp, ct_ref, ref_src='uqr', cmp_enddate=''): ct_mod = "%s / %s" % (ct_cmp, ct_ref) title = ct_mod if ct_mod == "j / jm": title = "j - jm*1.33" beginDate, endDate = '20130101', '20190101' fields = 'closePrice ticker openInt turnoverVol mainCon smainCon tradeDate'.split() fields_cmp = fields + ['highestPrice', 'lowestPrice'] df2 = read_uqr_HangQing(ct_cmp, beginDate, endDate) df2 = df2.loc[:, fields_cmp] if cmp_enddate: df2 = df2.loc[:cmp_enddate] if ref_src == "uqr": df_ref = read_uqr_HangQing(ct_ref, beginDate, endDate) df_ref = df_ref.loc[:, fields] df_ref = df_ref[df_ref['ticker'].str.match('^' + ct_ref + '\d+')] prefix = '1' if ct_ref == ct_ref.upper() else '' df_ref['cdate'] = df_ref['ticker'].apply(lambda xx: prefix + re.sub('[a-zA-Z]', '', xx, 0)) df_ref = df_ref.drop_duplicates(subset=['tradeDate', 'cdate']) if ct_ref in ["rb", "hc"]: df_ref['cdate'] = df_ref['cdate'].apply(lambda xx: xx[:-2] + '09' if xx[-2:] == '10' else xx[:-2] + '09d' if xx[-2:] == '09' else xx) df_ref.set_index(['tradeDate', 'cdate'], inplace=True) df_ref = df_ref.sort_index() if ref_src == "OANDA": df_ref = pd.read_csv('../../data/df_%s.csv' % ct_ref, index_col=[0]) df_f = read_mc_ct2df('HangQing_investing_byD1', '_id', 'tradeDate', condition={'ticker': 'USD_CNY'}, db="Oanda_info") df_f.index = df_f['tradeDate'] # print df_f.tail(10) df_ref['cl'] = df_ref['cl'] * df_f['cl'] df_ref['turnoverVol'] = 10000 df_ref['closePrice'] = df_ref['cl'] df_ref['ticker'] = ct_ref # print (df_ref.tail(300)) df_cmp = df2[df2['ticker'].str.match('^' + ct_cmp + '\d+')] prefix = '1' if ct_cmp == ct_cmp.upper() else '' df_cmp['cdate'] = df_cmp['ticker'].apply(lambda xx: prefix + re.sub('[a-zA-Z]', '', xx, 0)) if ct_cmp == "FG": df_cmp['cdate'] = df_cmp['cdate'].apply(lambda xx: xx[:2] + '10x' if xx[-2:] == '10' else xx[:2] + '10' if xx[-2:] == '09' else xx) df_cmp['cdate'] = df_cmp['cdate'].apply(lambda xx: '1505x' if xx == '1505' else '1505' if xx == '1506' else xx) if ct_cmp == "MA": pass if ct_cmp in ["rb", "hc"]: df_cmp['cdate'] = df_cmp['cdate'].apply(lambda xx: xx[:-2] + '09' if xx[-2:] == '10' else xx[:-2] + '09d' if xx[-2:] == '09' else xx) # if ref_src=="uqr": df_cmp = df_cmp.drop_duplicates(subset=['tradeDate', 'cdate']) df_cmp.set_index(['tradeDate', 'cdate'], inplace=True) df_cmp = df_cmp[df_cmp['mainCon'] == 1] if ref_src == "OANDA": df_cmp.index = df_cmp.index.get_level_values(0) # df_cmp = df_cmp[df_cmp['mainCon'] == 1] # df_cmp = df_cmp.drop_duplicates(subset=['tradeDate']) # del df_cmp['cdate'] # df_cmp.set_index(['tradeDate'], inplace=True) # df_comp = oanda_cand(ct_cmp) # pass df_cmp = df_cmp.sort_index() df_cmp.columns = ['cmp_cl', 'cmp_tick', 'cmp_opInt', 'cmp_tv', 'cmp_main', 'cmp_smain', 'cmp_hi', 'cmp_lo'] print(df_ref.tail(3)) print(df_cmp.tail(3)) df = pd.concat([df_ref, df_cmp], axis=1) df['cmp_tv'] = df['cmp_tv'].fillna(0) df = df[df['cmp_tv'] > 3000] # print df df['diff'] = df['cmp_cl'] / df['closePrice'] # *2.5 if ct_mod == "cs / c": df['diff'] = df['cmp_cl'] - df['closePrice'] if ct_mod == "j / jm": df['diff'] = df['cmp_cl'] - 1.33 * df['closePrice'] if ct_mod == "j / jm": df['diff'] = df['cmp_cl'] - 3 * df['closePrice'] / 1.66 if ct_mod == "cu / XCU_USD": df['diff'] = df['cmp_cl'] / (2204 * df['closePrice']) if ct_mod == "SR / SUGAR_USD": df['diff'] = df['cmp_cl'] / (2204 * df['closePrice']) if ct_mod == "a / SOYBN_USD": df['diff'] = df['cmp_cl'] / (36.9 * df['closePrice']) if ct_mod == "c / CORN_USD": df['diff'] = df['cmp_cl'] / (39.37 * df['closePrice']) if ct_mod == "au / XAU_USD": df['diff'] = df['cmp_cl'] / (df['closePrice'] / 31.3) if ct_mod == "ag / XAG_USD": df['diff'] = df['cmp_cl'] / (df['closePrice'] * 1000 / 31.3) df['dt'] = df.index.get_level_values(0) df['dt'] = df['dt'].astype('str') df = df[~df['diff'].isnull()] df['diff'] = df['diff'].apply(lambda xx: round(xx, 3)) if ct_ref == 'c': df.loc[(df['dt'] >= '2015-06-23') & (df['dt'] <= '2015-08-17'), 'mainCon'] = 0 df.loc[(df['dt'] >= '2015-06-23') & (df['dt'] <= '2015-08-17') & (df['ticker'] == 'c1601'), 'mainCon'] = 1 # df.loc[(df['dt']>='2017-10-01'), 'mainCon'] = 0 # df.loc[(df['dt']>='2017-10-01') & (df['ticker'] == 'c1805'), 'mainCon'] = 1 page = Page('期货套利') line1 = Line("%s" % ct_cmp, width=1200, height=400) line1.add( "%s" % ct_cmp, df['dt'].tolist(), df['cmp_cl'].tolist(), yaxis_min=min(df['cmp_cl'].tolist()), yaxis_max=max(df['cmp_cl'].tolist()), tooltip_trigger="axis", tooltip_axispointer_type='cross', mark_line=["max", 'average', 'min'], mark_point=["max", 'min'], mark_point_symbol="circle", mark_point_symbolsize=35, legend_top="3%", is_smooth=True, line_color='#632418', line_width=2.5, is_more_utils=True # yaxis_type="log", ) page.add(line1) line2 = Line("%s" % ct_ref, width=1200, height=400) line2.add( "%s" % ct_ref, df['dt'].tolist(), df['closePrice'].tolist(), yaxis_min=min(df['closePrice'].tolist()), yaxis_max=max(df['closePrice'].tolist()), tooltip_trigger="axis", tooltip_axispointer_type='cross', mark_line=["max", 'average', 'min'], mark_point=["max", 'min'], mark_point_symbol="circle", mark_point_symbolsize=35, legend_top="3%", is_smooth=True, line_color='#5296de', line_width=2.5, is_more_utils=True # yaxis_type="log", ) page.add(line2) line3 = Line("{}-{}套利".format(ct_cmp, ct_ref), width=1200, height=400) line3.add( "日收益", df['dt'].tolist(), df['diff'].tolist(), yaxis_min=min(df['diff'].tolist()), yaxis_max=max(df['diff'].tolist()), yaxis_interval=1, tooltip_trigger="axis", tooltip_axispointer_type='cross', mark_line=["max", 'average', 'min'], mark_point=["max", 'min'], mark_point_symbol="circle", mark_point_symbolsize=35, legend_top="3%", is_smooth=True, line_color='#082039', line_width=3, is_more_utils=True # yaxis_type="log", ) page.add(line3) line3.render(PIC_FILE_PATH + 'main_{}-{}.png'.format(ct_cmp, ct_ref)) page.render(FILE_DIR + 'main_{}-{}.html'.format(ct_cmp, ct_ref))
print(days) bar = Bar('工作细胞柱状图',title_pos='center',width=900) bar.add("",month,df3.values,mark_point=['max','min'],is_visualmap=True) page.add(bar) bar1 = Bar('工作细胞一周内的评论情况',title_pos='center',title_top='bottom',width=900) bar1.add("",days.index,days.values,mark_point=['max','min'],mark_line=['average']) page.add(bar1) pie = Pie("工作细胞圆饼图",title_pos='center',width=900,title_top='bottom') pie.add("",month,df3.values,is_label_show=True,is_legend_show=True,radius=[30,75]) page.add(pie) page.render('工作细胞.html') ''' day_list = sorted(list(df3.index),key=lambda x:datetime.datetime.strptime(x,'%Y/%m/%d').timestamp()) print(df3) print(df3['2018/7/8']) list1 = list(map(lambda x:x.split('/',1)[1],day_list)) list2=[] for i,x in enumerate(list1): if i%15==0: list2.append(list1[i]) else: list2.append('') plt.title('Commentary heat') plt.bar(list(map(lambda x:x.split('/',1)[1],day_list)),df3[day_list]) for x,y in zip(list1,df3[day_list]):
from pyecharts import Bar,Line,Overlap, Page import pandas as pd import random import numpy as np page = Page() xline = pd.date_range(start='12/1/2018', periods=10) #v1 = random.sample(range(100), 10) #v2 = random.sample(range(100), 10) v1 = [10,20,30,40,50,60,40,80,30,20] v2 = [38,28,35,58,65,70,20,40,90,10] bar = Bar('Line - Bar示例') bar.add('bar',xline,v1) line = Line() line.add('line',xline,v2) overlop = Overlap() overlop.add(bar) overlop.add(line) page.add(overlop) page.render('./picture11a.html')
yaxis_max=0.8) overlap = Overlap(width=900, height=400) overlap.add(bar) overlap.add(line, is_add_yaxis=True, yaxis_index=1) return overlap ##数据可视化 from pyecharts import Page page = Page() for col in train.columns[1:]: page.add(get_chatrs(train, col)) page.render('pages.html') page train['Attrition'].mean() # 在分析中发现有一些字段的值是单一的,进一步验证 single_value_feature = [] for col in train.columns: lenght = len(train[col].unique()) if lenght == 1: single_value_feature.append(col) single_value_feature # ['Over18', 'StandardHours'] # 删除这两个字段 train.drop(['Over18', 'StandardHours'], axis=1, inplace=True) train.shape # (1100, 28)
visual_text_color='#000', is_label_show=True, label_text_size=20, label_formatter='{b}:{c}', legend_text_size=22) page.add(map) map1 = Map("地图", title_text_size=30) map1.add("国外大学发文分布", [ 'United Kingdom', 'United States', 'German', 'Italy', 'Russia', 'Netherland' ], [2, 6, 3, 1, 1, 1], visual_range=[0, 6], maptype="world", is_visualmap=True, visual_text_color='#021', label_text_size=20, label_formatter='{b}:{c}', legend_text_size=22) page.add(map1) bar = Bar("统计图", title_text_size=30) bar.add("机构发文信息(降序排列)", ['中国科学院', '中国社科院', '中国人民银行', '中国农业银行', '其他机构(共43篇)'], [23, 10, 8, 5, 1], is_stack=True, xaxis_interval=0, legend_text_size=22) page.add(bar) page.render('map.html')
def graphpage(labels,mode_combo,startdate,enddate,optInterval,width1, height1): #optInterval='D/W/M' labels startdate = startdate.replace("/","-")#convert to tushare readable date enddate = enddate.replace("/","-") page = Page() for label in labels: # generate numbers of graphs according to numbers of queries in treewidget label1 = re.split("-", label) overlap = Overlap() if label1[2]!="分笔" and label1[2]!="季度饼图": #"K线" "复权" "历史分钟" if mode_combo == "复权": #if optInterval == "qfq" or optInterval == "hfq":#复权 array = ts.get_h_data(label1[1], start=startdate, end=enddate, autype="qfq") array = array.sort_index() time = array.index.format() # 日期正是index elif mode_combo == "K线": #elif optInterval.isalnum() :#历史K线 array = ts.get_k_data(label1[1], start=startdate, end=enddate, ktype=optInterval) time = array['date'].tolist() # array.date elif mode_combo == "历史分钟": array_bfr = ts.get_tick_data(label1[1], date=startdate) array_bfr.sort_values("time") a = startdate + " " + array_bfr["time"] array_bfr["time"] = a array_bfr["time"] = pd.to_datetime(a) array_bfr = array_bfr.set_index("time") if label1[2] != "Volume" and label1[2] != "Amount": price_df = array_bfr["price"].resample(optInterval).ohlc() # resample重新取样,选出ohlc=open/high/low,提取除价格之外另外4列.close,tushare是ohcl price_df = price_df.dropna() array = price_df time = price_df.index.format() elif label1[2] == "Volume": vols = array_bfr["volume"].resample(optInterval).sum() #resample重新取样,累加间隔内数值 relevant data processing algorithm taken from Jimmy, Creator of Tushare vols = vols.dropna() vol_df = pd.DataFrame(vols, columns=["volume"]) array = vol_df time = vol_df.index.format() else: amounts = array_bfr["amount"].resample(optInterval).sum() amounts = amounts.dropna() amount_df = pd.DataFrame(amounts, columns=["amount"]) array = amount_df time = amount_df.index.format() #绘图方法 if label1[2] == 'Kline': re_array = array[['open', 'close', 'high', 'low']] data_li = list(row.tolist() for index, row in re_array.iterrows()) # data_list = list(re_array.as_matrix()) close = array['close'].tolist() kline = Kline(label1[0] + "-" + optInterval, width=width1*10/11, height = (height1*10/11) / len(labels)) kline.add(label1[0], time, data_li, is_datazoom_show=True, datazoom_type="slider", yaxis_interval=1) overlap.add(kline) if len(close) > 10: ma10 = calculateMa(close, 10) line1 = Line(title_color="#C0C0C0") line1.add(label1[0] + "-" + "MA10", time, ma10) overlap.add(line1) if len(close) > 20: ma20 = calculateMa(close, 20) line2 = Line(title_color="#C0C0C0") line2.add(label1[0] + "-" + "MA20", time, ma20) overlap.add(line2) if len(close) > 30: ma30 = calculateMa(close, 30) line3 = Line(title_color="#C0C0C0") line3.add(label1[0] + "-" + "MA30", time, ma30) overlap.add(line3) page.add(overlap) else:#When label1[2]==open/close/volume if label1[2] == 'Open': list_aft = array['open'].tolist() elif label1[2] == 'Close': list_aft = close elif label1[2] == 'High': list_aft = array['high'].tolist() elif label1[2] == 'Low': list_aft = array['low'].tolist() elif label1[2] == 'Volume':#volume list_aft = array['volume'].tolist() else:#amount list_aft = array['amount'].tolist() line = Line(label1[0] + "-" + label1[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels)) line.add(label1[0] + "-" + label1[2], time, list_aft, is_datazoom_show=True, yaxis_max="dataMax", yaxis_min="dataMin", datazoom_type="slider") overlap.add(line) page.add(overlap) elif label1[2]=="分笔": array = ts.get_tick_data(label1[1], date=startdate) array = array.sort_values("time") date = array["time"].tolist() amount = array["amount"].tolist() atype = array["type"].tolist() price = array["price"].tolist() flag = ["bar" for i in date] for idx, val in enumerate(atype): if val == "卖盘": amount[idx] = -amount[idx] if val == "中性盘": amount[idx] = 0 returnarray = list(zip(date, amount, flag, price)) form = [e[1] for e in returnarray] time = [d[0] for d in returnarray] bar = Bar(label1[0] + "-" + label1[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels)) bar.add(label1[0] + "-" + label1[2], time, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax") overlap.add(bar) line = Line(label1[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels)) price = [e[3] for e in returnarray] line.add(label1[0] + "price", time, price, yaxis_min="dataMin", yaxis_max="dataMax", is_datazoom_show=True, datazoom_type="slider", yaxis_type="value") overlap.add(line, yaxis_index=1, is_add_yaxis=True) page.add(overlap) elif label1[2]=="季度饼图": datestr = startdate.split("-") thisyear = datestr[0] df2 = ts.top10_holders(code=label1[1], gdtype="1") test = df2[1]["quarter"].tolist() df_ready = df2[1] idxlist = [] for idx, val in enumerate(test): a = val.split("-") if a[0] == thisyear: # print a[0],idx idxlist.append(idx) thing = df_ready.loc[idxlist] thing = thing.sort_values(["quarter", "name"]) # print a[0],id name = thing["name"].tolist() value = thing["hold"].tolist() quarter = thing["quarter"].tolist() namearray = [name[i:i + 10] for i in range(0, len(name), 10)] valuearray = [value[j:j + 10] for j in range(0, len(value), 10)] quarterarray = [quarter[k:k + 10] for k in range(0, len(quarter), 10)] flag = ["pie" for i in namearray] num = [len(value) for k in namearray] returnarray = list(zip(namearray, valuearray, quarterarray, flag, num)) timeline = Timeline(is_auto_play=False, timeline_bottom=0) # zip(namearray,valuearray,quarter,flag,num) namearray = [c[0] for c in returnarray] valuearray = [d[1] for d in returnarray] quarter = [e[2] for e in returnarray] num = returnarray[0][4] for x in range(0, int(num / 10)): list1 = valuearray[x] names = namearray[x] quarters = quarter[x][0] for idx, val in enumerate(list1): list1[idx] = float(val) pie = Pie(label1[0] + "-" + "前十股东", width=width1 * 10 / 11, height=(height1 * 10 / 11)) pie.add(label1[0] + "-" + "前十股东", names, list1, radius=[30, 55], is_legend_show=False, is_label_show=True, label_formatter="{b}: {c}\n{d}%") timeline.add(pie, quarters) # namearray = [y for y in namearray[x]] timeline.render() page.render()
def plot(df): kl = df.copy() kl['MID'] = (kl['HIGH'] + kl['LOW']) / 2 kl['AG13'] = kl['MID'].rolling(window=13).mean() kl['AG8'] = kl['MID'].rolling(window=8).mean() kl['AG5'] = kl['MID'].rolling(window=5).mean() kl['SMA5'] = kl['MID'].rolling(window=5).mean() kl['SMA34'] = kl['MID'].rolling(window=34).mean() kl['AO'] = kl['SMA5'] - kl['SMA34'] kl = kl[20:] for i in range(2, len(kl['MID'])): kl.ix[i, 'AG13'] = (kl.ix[i - 1, 'AG13'] * 12 + (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 13 kl.ix[i, 'AG8'] = (kl.ix[i - 1, 'AG8'] * 7 + (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 8 kl.ix[i, 'AG5'] = (kl.ix[i - 1, 'AG5'] * 4 + (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 5 kl['AG13'] = kl['AG13'].shift(8) kl['AG8'] = kl['AG8'].shift(5) kl['AG5'] = kl['AG5'].shift(3) kl = kl.where(kl.notnull(), 0) kl['GTUP'] = abs(kl['AG13'] - kl['AG8']) kl['GTDOWN'] = abs(kl['AG8'] - kl['AG5']) kl['MUP'] = 0 kl['MDOWN'] = 0 markd = [] for i in range(2, len(kl['MID']) - 2): if kl.ix[i, 'HIGH'] == max(kl.ix[i - 2, 'HIGH'], kl.ix[i - 1, 'HIGH'], kl.ix[i, 'HIGH'], kl.ix[i + 1, 'HIGH'], kl.ix[i + 2, 'HIGH']): #kl.ix[i,'MUP']=1 markd.append({ "coord": [kl.index[i], kl.ix[i, 'HIGH']], "name": "1" }) if kl.ix[i, 'LOW'] == min(kl.ix[i - 2, 'LOW'], kl.ix[i - 1, 'LOW'], kl.ix[i, 'LOW'], kl.ix[i + 1, 'LOW'], kl.ix[i + 2, 'LOW']): markd.append({ "coord": [kl.index[i], kl.ix[i, 'LOW']], "name": "2" }) page = Page(page_title='AO') kline = Kline() kline.add('', list(kl.index), [ list(kl[['OPEN', 'CLOSE', 'LOW', 'HIGH']].iloc[i, ].values) for i in range(len(kl)) ], is_datazoom_show=True, datazoom_xaxis_index=[0, 1], datazoom_type="both", is_xaxislabel_align=True, tooltip_axispointer_type="cross", mark_point=markd, mark_point_symbol='circle', mark_point_symbolsize=10) line = Line(' ') line.add('JAW', list(kl.index), list(kl['AG13']), line_color=['#0000ff'], label_color=['#0000ff']) line.add('TEETH', list(kl.index), list(kl['AG8']), line_color=['#ff0000'], label_color=['#ff0000']) line.add('LIPS', list(kl.index), list(kl['AG5']), line_color=['#00ff00'], label_color=['#00ff00']) overlap1 = Overlap() overlap1.add(kline) overlap1.add(line) #gator # bar1 = Bar(' ') # bar2 = Bar(' ') # up = list(kl['GTUP']) # down = list(kl['GTDOWN']) # redup = [] # greenup = [] # reddown = [] # greendown = [] # for i in range(len(up)): # if (i == 0): # greenup.append(up[i]) # redup.append(0) # greendown.append(-down[i]) # reddown.append(0) # continue # if (up[i] > up[i - 1]): # greenup.append(up[i]) # redup.append(0) # else: # greenup.append(0) # redup.append(up[i]) # if (down[i] > down[i - 1]): # greendown.append(-down[i]) # reddown.append(0) # else: # greendown.append(0) # reddown.append(-down[i]) # # # bar.add('MACDhist',klt,macd[2].tolist(),is_datazoom_show=True,legend_top='65%') # bar1.add('GTREDUP', list(kl.index), redup, legend_top='65%', label_color=['#ff0000']) # bar2.add('GTREDDOWN', list(kl.index), reddown, legend_top='65%', label_color=['#00ff00']) # bar1.add('GTGREENUP', list(kl.index), greenup, legend_top='65%', label_color=['#ff0000']) # bar2.add('GTGREENDOWN', list(kl.index), greendown, legend_top='65%', label_color=['#00ff00']) bar1 = Bar(' ') bar2 = Bar(' ') ao = list(kl['AO']) aor = [] aog = [] for i in range(len(ao)): if (i == 0): aor.append(ao[i]) aog.append(0) continue if ao[i] > ao[i - 1]: aor.append(0) aog.append(ao[i]) else: aor.append(ao[i]) aog.append(0) bar1.add('AOR', list(kl.index), aor, legend_top='65%', label_color=['#ff0000']) bar2.add('AOG', list(kl.index), aog, legend_top='65%', label_color=['#00ff00']) overlap2 = Overlap() overlap2.add(bar1) overlap2.add(bar2) grid = Grid(width=1920, height=950) grid.add(overlap1, grid_bottom='40%') grid.add(overlap2, grid_top='70%') # page.add(line) # page.add(overlap) page.add(grid) path = os.path.abspath('.') page.render(path + '\\plot\\AO.html')
'ts_name': "隆基股份" }, { 'ts_code': '002129.SZ', 'ts_name': "中环股份" }, { 'ts_code': '300274.SZ', 'ts_name': "阳光电源" }, { 'ts_code': '600438.SH', 'ts_name': "通威股份" }] page = Page() for stock in stock_list: line = Line(stock['ts_name'], width=1600, height=800) df = ts.pro_bar(pro_api=pro, ts_code=stock['ts_code'], adj='qfq', start_date=startDate, end_date=endDate) if df is not None: df = df.sort_index(ascending=True) line.add(stock['ts_name'], df['trade_date'], df['close'], mark_point=["max", "min"], mark_point_symbolsize=70) page.add_chart(line) page.render('market_daily.html')
def graphpage(items, startdate, enddate, option, width1, height1): page = Page() for i in items: #generate numbers of graphs according to numbers of queries in treewidget j = re.split("-", i) if len(j) == 3: a = generateline( j[1], j[2], startdate, enddate, option ) #stock number, Type, startdate, enddate, 30 or 15 or days if a is None: continue time = [d[0] for d in a] #get time from returned dictionary if j[2] != "Kline": if len(a[0]) == 4 and a[0][2] == "bar": #for 分笔data overlap = Overlap() form = [e[1] for e in a] bar = Bar(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(j[0] + "-" + j[2], time, form, yaxis_min="dataMin", yaxis_max="dataMax", is_datazoom_show=True, datazoom_type="slider") overlap.add(bar) line = Line(j[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in a] line.add(j[0] + "price", time, price, yaxis_min="dataMin", yaxis_max="dataMax", is_datazoom_show=True, datazoom_type="slider", yaxis_type="value") overlap.add(line, yaxis_index=1, is_add_yaxis=True) page.add(overlap) #need more statement else: form = [e[1] for e in a] #for not分笔 data line = Line(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) line.add(j[0] + "-" + j[2], time, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax") page.add(line) else: overlap = Overlap() #for k线 close = zip(*a)[2] candle = [[x[1], x[2], x[3], x[4]] for x in a] candlestick = Kline(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) candlestick.add(j[0], time, candle, is_datazoom_show=True, datazoom_type="slider", yaxis_interval=1) overlap.add(candlestick) if len(close) > 10: ma10 = calculateMa(close, 10) line1 = Line(title_color="#C0C0C0") line1.add(j[0] + "-" + "MA10", time, ma10) overlap.add(line1) if len(close) > 20: ma20 = calculateMa(close, 20) line2 = Line(title_color="#C0C0C0") line2.add(j[0] + "-" + "MA20", time, ma20) overlap.add(line2) if len(close) > 30: ma30 = calculateMa(close, 30) line3 = Line(title_color="#C0C0C0") line3.add(j[0] + "-" + "MA30", time, ma30) overlap.add(line3) page.add(overlap) else: for k in range(1, len(j) / 3): #if graphs are combined j[3 * k - 1] = re.sub("\n&", "", j[3 * k - 1]) sizearray = [] #if j[1] != "Candlestick" layout = Overlap() for i in xrange(0, len(j), 3): array = j[i:i + 3] b = generateline(array[1], array[2], startdate, enddate, option) if b is None: continue btime = [d[0] for d in b] if array[2] != "Kline": if len(b[0]) == 4 and b[0][2] == "bar": form = [e[1] for e in b] bar = Bar(array[0] + "-" + array[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(array[0] + "-" + array[2], btime, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax") layout.add(bar) line = Line(array[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in b] line.add(array[0] + "price", btime, price, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_type="value") layout.add(line, yaxis_index=1, is_add_yaxis=True) else: line = Line(array[0] + "-" + array[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) line.add(array[0] + "-" + array[2], btime, b, is_datazoom_show=True, yaxis_max="dataMax", yaxis_min="dataMin", datazoom_type="slider") layout.add(line) else: candle = [[x[1], x[2], x[3], x[4]] for x in b] candlestick = Kline(array[0] + "-" + array[1], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) candlestick.add(array[0], btime, candle, is_datazoom_show=True, datazoom_type=["slider"]) #if i == 0: close = zip(*b)[2] if len(close) > 10: ma10 = calculateMa(close, 10) line4 = Line(title_color="#C0C0C0") line4.add(array[0] + "-" + "MA10", btime, ma10) layout.add(line4) if len(close) > 20: ma20 = calculateMa(close, 20) line5 = Line(title_color="#C0C0C0") line5.add(array[0] + "-" + "MA20", btime, ma20) layout.add(line5) if len(close) > 30: ma30 = calculateMa(close, 30) line6 = Line(title_color="#C0C0C0") line6.add(array[0] + "-" + "MA30", btime, ma30) layout.add(line6) layout.add(candlestick) page.add(layout) page.render()
def tna_missing_allgraph(df_key_initial, df_key_ongoing, df_key_bar_result, df_key_bar_index, line): df_key_bar_result_charts = df_key_bar_result.set_index( 'ExpectedUpdateDate') df_key_bar_result_charts['Total'] = df_key_bar_result_charts.apply( lambda x: x.sum(), axis=1) df_key_bar_result_charts_final = pd.merge( df_key_bar_index, df_key_bar_result_charts, on=['ExpectedUpdateDate'], how='outer', ).fillna(0) # Merge 一起,用非周末的月份 Time_bar_x = [] for x_bar_time in df_key_bar_result_charts_final.ExpectedUpdateDate: # 取出x轴 x_bar_time = x_bar_time.strftime("%m-%d") Time_bar_x.append(x_bar_time) Ongoing_missing = df_key_bar_result_charts_final[ 'Ongoing missing'].to_list() # 转换 df 元素到list Three_month_Missing = df_key_bar_result_charts_final[ 'TNA is not available within 3 month'].to_list() # 转换 df 元素到list Six_month_Missing = df_key_bar_result_charts_final[ 'TNA is not available within 6 month'].to_list() # 转换 df 元素到list Total_line = df_key_bar_result_charts_final.Total.to_list( ) # 转换 df 元素到list page = Page() #---开始画Bar--- bar = Bar('Missing', background_color='white', title_text_size=15, width='100%') bar.add("Ongoing", Time_bar_x, Ongoing_missing, is_stack=True, is_more_utils=True) # is_more_utils = True 这个是开启多个小工具 bar.add("3 M", Time_bar_x, Three_month_Missing, is_stack=True, is_more_utils=True) bar.add("6 M", Time_bar_x, Six_month_Missing, is_stack=True, is_more_utils=True) line_bar = Line('Total', background_color='white', title_text_size=15, width='100%') line_bar.add("Total", Time_bar_x, Total_line, is_fill=False, area_opacity=0.001, is_more_utils=True) overlap = Overlap(width='100%') # 把 line 和bar overlap一起 overlap.add(bar) overlap.add(line_bar) #overlap.render() page.add_chart(overlap) # 把 所有page 一起 page.add_chart(line) page.render( r'\\szmsfs03\Shared\Global Fund\Public folder\Performance & VA & ETF sharing\Performance AI Study Group\Python Code\PublicData_project1\TNA_missing\TNA_Report.html' ) with tqdm_notebook(total=100) as pbar: pbar.update(90)
def test_more(): page = Page() # line attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line = Line("折线图示例") line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"]) page.add(line) # pie attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos='center') pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(pie) # kline v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22]] kline = Kline("K 线图示例") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1) page.add(kline) # radar schema = [("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000)] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') page.add(radar) page.render()
def statanalysis(): ###----------------数据准备-------------------------- #打开数据 h = pd.read_excel(path1) #找出所选择的客户数据 i = h[h['客户姓名'] == a] print(i) ####---------------------!!!!------------ i0 = i['项目名称'].value_counts() print(i0) i00 = i0.to_frame() i00['项目名称'] = i00.index i00 = i00.reset_index(drop= True) i000 = i['项目名称'].value_counts().tolist() i00['训练次数'] = i000 print(i0) print(i00) i2 = i['课程类型'].tolist()[0] page = Page(page_title=a) ##---------------radar图数据准备---------------------- #对客户数据进行分组求和 j = i.groupby(by=['项目名称'])['客户成绩'].mean() #查看j的类型 #print(type(j)) #把series转换为frame k = j.to_frame() #取出K中索引,生成新一列,去掉k中索引 k['项目名称'] = k.index k = k.reset_index(drop= True) print(k) l = i.groupby(by=['项目名称'])['客户成绩'].max() n = l.to_frame() n['项目名称'] = n.index n = n.reset_index(drop = True) ##--------------------radar图数据准备-------------------- ##-------------------------合并dataframe----------------- diantu = pd.merge(i00,k,how = 'inner') print(diantu) ##-------------------------合并dataframe----------------- ##-------------------- line数据准备----------------- Dgkhxm = i.drop_duplicates(['项目名称']) Dgkhxm_list =Dgkhxm['项目名称'].tolist() #print(Dgkhxm) #print(Dgkhxm_list) Dgkhxm_len = len(Dgkhxm_list) #print(Dgkhxm_len) i1 = i[i['项目名称'] == b] #print(i1) ##-------------------line数据准------------------------ ###----------------数据准备----------------------------------------- ##---------------------词云---------------------------------- name = [i2,a] value = [55,50] wordcloud = WordCloud('客户基本信息',width=600, height=320) wordcloud.add("", name, value,word_size_range=[20, 25],shape='diamond') page.add(wordcloud) ##------------------------词云----------------------------------- #-----------------radar图-------------------------------- schema = [] for aa in k['项目名称'].tolist(): aa = (aa,100) schema.append(aa) v_pingjun = [] v_pingjun.append(k['客户成绩'].tolist()) v_zuida =[] v_zuida.append(n['客户成绩'].tolist()) #print(schema) #print(v_pingjun) #print(v_zuida) radar = Radar('客户成绩观星评测') radar.config(schema) radar.add("平均成绩",v_pingjun,is_splitline=True, is_axisline_show=True) radar.add("最好成绩", v_zuida, label_color=["#4e79a7"], is_area_show=False) page.add(radar) #------------------radar图------------------------------------- ##------------------------EffectScatter------------------------ cishu = diantu['训练次数'].tolist() chengji = diantu['客户成绩'].tolist() es = EffectScatter("训练次数&成绩") es.add("effectScatter", cishu, chengji,xaxis_name = '训练次数',yaxis_name = '客户成绩') page.add(es) ##------------------------EffectScatter------------------------ ##---------------------line-------------------------------- attr = i1['课程时间'].tolist() v_zoushi = i1['客户成绩'].tolist() line = Line(b) line.add(b, attr, v_zoushi, mark_line=["max", "average"]) page.add(line) page.render('简单统计分析结果报告.html')
Sex_counter[Sex_dict[friend['Sex']]] += 1 if friend['Province'] != "": Province_counter[friend['Province']] += 1 # tag extractor get_tag(friend['Signature'],Signature_counter) get_tag(friend['NickName'],NickName_counter) page = Page() # Sex name_list,num_list = dict2list(Sex_counter) page.add(get_pie('Gender',name_list,num_list)) # Province & Map name_list,num_list = counter2list(Province_counter.most_common(15)) page.add(get_bar('District',name_list,num_list)) page.add(get_map('Map',name_list,num_list)) # NickName name_list,num_list = counter2list(NickName_counter.most_common(200)) page.add(word_cloud('NickName',name_list,num_list,[20,50])) # Signature name_list,num_list = counter2list(Signature_counter.most_common(200)) page.add(word_cloud('Signature',name_list,num_list,[20,50])) page.render('./analyse/analyse.html') # Head Image mergeImage()
def test_more(): page = Page() # line line = Line("折线图示例") line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], ) # pie v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos='center') pie.add( "", CLOTHES, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left', ) page.add([line, pie]) # kline v1 = [ [2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22], ] kline = Kline("K 线图示例") kline.add( "日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, is_datazoom_show=True, ) page.add(kline) # radar schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000), ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add( "实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single', ) page.add(radar) # scatter3d import random data = [[ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100), ] for _ in range(80)] scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR) page.add(scatter3D) # wordcloud name = [ 'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break', ] value = [ 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265, ] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66) page.add(wordcloud) # liquid liquid = Liquid("水球图示例") liquid.add("Liquid", [0.6]) page.add(liquid) assert len(page) == 7 assert isinstance(page[0], Line) assert (('echarts' in page.js_dependencies) or ('echarts.min' in page.js_dependencies)) page.render()
import datetime url = "http://www.86pm25.com/paiming.htm" head = { 'Referer': 'http://www.86pm25.com/city/Dazhou.html', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' } html = requests.get(url, headers=head) html.encoding = 'utf-8' soup = BeautifulSoup(html.text, "lxml") data1 = soup.find(id="goodtable").find_all(name='a') data2 = str(soup.find(id='goodtable').find_all(name='td')) data = re.findall(r'<td>(\d{1,3}.)</td>', data2) with open("城市.txt", 'r') as f: CityList = f.read() city = [] for i in range(0, 367): if str(data1[i].string) in CityList: citytuple = (data1[i].string, int(data[i])) city.append(citytuple) geo = Geo("全国主要城市空气质量实时监控", "实时:" + str(datetime.datetime.now()), title_color="#fff", title_pos="center", width='100%', height=790, background_color='#404a59') attr, value = geo.cast(city) geo.add("", attr, value, visual_range=[0, 150], maptype='china', visual_text_color="#fff", symbol_size=13, is_visualmap=True) page = Page() page.add(geo) page.render("全国主要城市空气质量实时监控.html") webbrowser.open("全国主要城市空气质量实时监控.html", new=0, autoraise=True)
Source_name_list, Source_num_list = counter2list(Source_counter) Destination_name_list, Destination_num_list = counter2list(Destination_counter) for i in range(len(Source_name_list)): if Source_name_list[i] == 'Apple, Inc.': Source_num_list[i] = Source_num_list[i] + 1254 if Source_name_list[i] == 'Sagemcom Broadband SAS': Source_num_list[i] = Source_num_list[i] + 5024 for i in range(len(Destination_name_list)): if Destination_name_list[i] == 'Apple, Inc.': Destination_num_list[i] = Destination_num_list[i] + 4141 if Destination_name_list[i] == 'Sagemcom Broadband SAS': Destination_num_list[i] = Destination_num_list[i] + 1149 pie1 = Pie('Source列的MAC归属机构', title_text_size=30, title_pos='center', \ width=1200, height=1500) pie1.add("", Source_name_list, Source_num_list, is_label_show=True, center=[50, 45], radius=[0, 50], \ legend_pos='right', legend_orient='vertical', label_text_size=20) pie2 = Pie('Destination列的MAC归属机构', title_text_size=30, title_pos='center', \ width=1200, height=1550) pie2.add("", Destination_name_list, Destination_num_list, is_label_show=True, center=[50, 45], radius=[0, 50], \ legend_pos='right', legend_orient='vertical', label_text_size=20) page = Page() page.add_chart(pie1) page.add_chart(pie2) page.render('result_merge.html')
def tochart(path): df = pd.read_excel(path, sheet_name=0, encoding='ANSI') df.reset_index() page = Page(page_title='7月事件单分析TOP10') #Bar bar = Bar(width=1000, height=700) collist = df.columns.values.tolist() fenlei = df[collist[0]] for col in range(1, len(collist) - 1): ds = collist[col] list2 = df[ds] bar.add(ds, fenlei, list2, is_stack=True, bar_category_gap='40%', xaxis_interval=0, xaxis_rotate=15, yaxis_rotate=30) page.add_chart(bar, name="bar") #词云图+饼图 top = "" num = 30 wordcloud = [] pie = [] for i in range(0, 3): keyword = [] value = [] top = fenlei[i] fenci.fenci(top, num, keyword, value) #调用fenci print(keyword, value) #词云图 wordcloud.append( WordCloud(title='↑关键词分析(TOP30):' + str(top), title_text_size=14, title_top='bottom', width=500, height=500)) wordcloud[i].add(top, keyword, value, word_size_range=[20, 60], shape='diamond') page.add_chart(wordcloud[i], name='wordcloud' + str(i)) #饼图 pie.append( Pie(title='↑关键词分析(TOP10):' + str(top), title_text_size=14, title_top='bottom', width=600, height=500)) pie[i].add(top, keyword[0:10], value[0:10], radius=[30, 60], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left") page.add_chart(pie[i], name='pie' + str(i)) print('-' * 10) page.render('7月事件单分析TOP10+关键词.html') return 0
def draw_citys_pic(csv_file): page = Page(csv_file + ":评论城市分析") info = count_city(csv_file) geo = Geo("", "Ctipsy原创", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") while True: # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计 try: attr, val = geo.cast(info) geo.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=6, symbol_size=15, is_visualmap=True) except ValueError as e: e = str(e) e = e.split("No coordinate is specified for ")[1] # 获取不支持的城市名称 info.pop(e) else: break info = sorted(info.items(), key=lambda x: x[1], reverse=False) # list排序 # print(info) info = dict(info) # list转dict # print(info) attr, val = [], [] for key in info: attr.append(key) val.append(info[key]) geo1 = Geo("", "评论城市分布", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff") geo1.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False, is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True) # geo1.render(csv_file + "_城市dotmap.html") page.add_chart(geo1) geo2 = Geo( "", "评论来源热力图", title_pos="center", width=1200, height=600, background_color='#404a59', title_color="#fff", ) geo2.add("", attr, val, type="heatmap", is_visualmap=True, visual_range=[0, 50], visual_text_color='#fff', is_more_utils=True) # geo2.render(csv_file+"_城市heatmap.html") # 取CSV文件名的前8位数 page.add_chart(geo2) bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600) bar.add("", attr, val, is_visualmap=True, visual_range=[0, 100], visual_text_color='#fff', mark_point=["average"], mark_line=["average"], is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45) # bar.render(csv_file+"_城市评论bar.html") # 取CSV文件名的前8位数 page.add_chart(bar) pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600) pie.add("", attr, val, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left') # pie.render(csv_file + "_城市评论Pie.html") # 取CSV文件名的前8位数 page.add_chart(pie) page.render(csv_file + "_城市评论分析汇总.html")
def graphpage(items,startdate,enddate,option,width1, height1): #labels:复权ork线or分笔 option:hfq, qfq or 15, 30, D, etc page = Page() is_has_content = False for i in items:#generate numbers of graphs according to numbers of queries in treewidget try: # i -> 600209-差价图 j = re.split("-", i) if len(j) == 2: a = generateline(j[0],j[1],startdate,enddate,option)#stock number, Type, startdate, enddate, 30 or 15 or days if a is None: continue is_has_content = True time = [d[0] for d in a]#get time from returned dictionary if j[1]!="Kline": # 历史分笔 if len(a[0])==4 and a[0][2]=="bar": #for 分笔data overlap = Overlap() form = [e[1] for e in a] bar = Bar(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(j[0] + "-" + j[2], time, form, yaxis_min = "dataMin",yaxis_max = "dataMax",is_datazoom_show = True, datazoom_type = "slider") overlap.add(bar) line = Line(j[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in a] line.add(j[0] + "price", time, price, yaxis_min = "dataMin",yaxis_max = "dataMax", is_datazoom_show = True, datazoom_type = "slider", yaxis_type="value") overlap.add(line,yaxis_index=1, is_add_yaxis=True) page.add(overlap) # 前10股东 if len(a[0])==5 and a[0][3]=="pie": overlap = Overlap() timeline = Timeline(is_auto_play=False, timeline_bottom=0) #zip(namearray,valuearray,quarter,flag,num) namearray = [c[0] for c in a] valuearray = [d[1] for d in a] quarter = [e[2] for e in a] num = a[0][4] for x in range(0, num / 10): list1 = valuearray[x] names = namearray[x] quarters = quarter[x][0] for idx, val in enumerate(list1): list1[idx] = float(val) pie = Pie(j[0]+"-"+"前十股东".decode("utf-8"),width=width1 * 10 / 11, height=(height1 * 10 / 11)) pie.add(j[0]+"-"+"前十股东".decode("utf-8"), names, list1, radius=[30, 55], is_legend_show=False, is_label_show=True, label_formatter = "{b}: {c}\n{d}%") # print list # print names # print quarterarray timeline.add(pie, quarters) # namearray = [y for y in namearray[x]] timeline.render() return #need more statement else: overlap = Overlap() if j[1] == "差价图".decode("utf-8"): benchmark = zip(*a)[2] line7 = Line(title_color="#C0C0C0") line7.add("benchmark", time, benchmark) overlap.add(line7) if j[1] == "价格指数".decode("utf-8"): price300_list = zip(*a)[2] line7 = Line(title_color="#C0C0C0") line7.add("沪深300-价格指数", time, price300_list) overlap.add(line7) form = [e[1] for e in a]#for not分笔 data line = Line(j[0] + "-" + j[1], width=width1*10/11, height=(height1*10/11)/len(items)) line.add(j[0] + "-" + j[1], time, form, is_datazoom_show=True, datazoom_type="slider",yaxis_min="dataMin",yaxis_max="dataMax") overlap.add(line) page.add(overlap) else: overlap = Overlap()#for k线 close = zip(*a)[2] candle = [[x[1], x[2], x[3], x[4]] for x in a] candlestick = Kline(j[0] + "-" + j[1], width=width1*10/11, height = (height1*10/11) / len(items)) candlestick.add(j[0], time, candle, is_datazoom_show=True, datazoom_type="slider",yaxis_interval = 1) overlap.add(candlestick) if len(close)>10: ma10 = calculateMa(close, 10) line1 = Line(title_color="#C0C0C0") line1.add(j[0] + "-" + "MA10", time, ma10) overlap.add(line1) if len(close)>20: ma20 = calculateMa(close, 20) line2 = Line(title_color="#C0C0C0") line2.add(j[0] + "-" + "MA20", time, ma20) overlap.add(line2) if len(close)>30: ma30 = calculateMa(close, 30) line3 = Line(title_color="#C0C0C0") line3.add(j[0] + "-" + "MA30", time, ma30) overlap.add(line3) page.add(overlap) else: for k in range(1, len(j)/3):#if graphs are combined j[3*k-1] = re.sub("\n&","",j[3*k-1]) sizearray=[] #if j[1] != "Candlestick" layout = Overlap() for i in xrange(0, len(j),3): array = j[i:i + 3] b = generateline(array[1],array[2],startdate,enddate,option) if b is None: continue btime = [d[0] for d in b] if array[2] != "Kline": if len(b[0])==4 and b[0][2]=="bar": form = [e[1] for e in b] bar = Bar(array[0] + "-" + array[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) bar.add(array[0] + "-" + array[2], btime, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax") layout.add(bar) line = Line(array[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items)) price = [e[3] for e in b] line.add(array[0] + "price", btime, price, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_type="value") layout.add(line, yaxis_index=1, is_add_yaxis=True) else: line = Line(array[0] + "-" + array[2],width=width1*10/11, height=(height1*10/11) / len(items)) line.add(array[0]+"-"+array[2], btime, b, is_datazoom_show=True, yaxis_max = "dataMax", yaxis_min = "dataMin",datazoom_type="slider") layout.add(line) else: candle = [[x[1], x[2], x[3], x[4]] for x in b] candlestick = Kline(array[0] + "-" + array[1], width=width1*10/11, height=(height1*10/11) / len(items)) candlestick.add(array[0], btime, candle, is_datazoom_show=True, datazoom_type=["slider"]) #if i == 0: close = zip(*b)[2] if len(close)>10: ma10 = calculateMa(close, 10) line4 = Line(title_color="#C0C0C0") line4.add(array[0] + "-" + "MA10", btime, ma10) layout.add(line4) if len(close)>20: ma20 = calculateMa(close, 20) line5 = Line(title_color="#C0C0C0") line5.add(array[0] + "-" + "MA20", btime, ma20) layout.add(line5) if len(close)>30: ma30 = calculateMa(close, 30) line6 = Line(title_color="#C0C0C0") line6.add(array[0] + "-" + "MA30", btime, ma30) layout.add(line6) layout.add(candlestick) page.add(layout) except Exception as e: print(e) global times if is_has_content is False: return today_path = '../data/' + str(datetime.date.today()) if os.path.exists(today_path) is False: os.mkdir(today_path) file_name = today_path + '/' + str(times) + '.html' times += 1 page.render(file_name)
# encoding: utf-8 import time import sys reload(sys) sys.setdefaultencoding('utf-8') from pyecharts import Bar, Scatter3D from pyecharts import Page page = Page() # step 1 # bar attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", attr, v1, is_stack=False) bar.add("商家B", attr, v2, is_stack=False) page.add(bar) # step 2 # scatter3D # import random # data = [[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)] # range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', # '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'] # scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) # scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) # page.add(scatter3D) # step 2 page.render() # step 3
def test_page_grid_timeline_overlap(): # Grid v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%") bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%") line = Line("折线图示例") line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", ) v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter("散点图示例", title_top="50%", title_pos="65%") scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%") es = EffectScatter("动态散点图示例", title_top="50%") es.add( "es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_top="50%", legend_pos="20%", ) grid = Grid() grid.add(bar, grid_bottom="60%", grid_left="60%") grid.add(line, grid_bottom="60%", grid_right="60%") grid.add(scatter, grid_top="60%", grid_left="60%") grid.add(es, grid_top="60%", grid_right="60%") # Timeline bar_1 = Bar("2012 年销量", "数据纯属虚构") bar_1.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_1.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2 = Bar("2013 年销量", "数据纯属虚构") bar_2.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_2.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3 = Bar("2014 年销量", "数据纯属虚构") bar_3.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_3.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4 = Bar("2015 年销量", "数据纯属虚构") bar_4.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_4.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5 = Bar("2016 年销量", "数据纯属虚构", height=720, width=1200) bar_5.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)]) bar_5.add( "冬季", CLOTHES, [randint(10, 100) for _ in range(6)], is_legend_show=True, ) timeline = Timeline(is_auto_play=True, timeline_bottom=0) timeline.add(bar_1, "2012 年") timeline.add(bar_2, "2013 年") timeline.add(bar_3, "2014 年") timeline.add(bar_4, "2015 年") timeline.add(bar_5, "2016 年") # Overlap attr = ["{}月".format(i) for i in range(1, 13)] v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3] v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3] v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2] bar = Bar(height=720, width=1200) bar.add("蒸发量", attr, v1) bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250) line = Line() line.add("平均温度", attr, v3, yaxis_formatter=" °C") overlap = Overlap() overlap.add(bar) overlap.add(line, yaxis_index=1, is_add_yaxis=True) page = Page() page.add(grid) page.add(timeline) page.add(overlap) page.render()
def main(): print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) tr.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) for t in range(0, Round): # 嗅探抓包 wlan = sniff(iface='WLAN', count=Cnt) s = str(wlan) print(wlan) print(wlan.show()) # wrpcap('packet.cap', wlan) # 提取数据 v3 = re.findall(r"\d+\.?\d*", s) for i in range(0, len(v3)): v1[i] += int(v3[i]) for i in range(0, len(wlan)): try: if 'IPv6' in wlan[i]: v2[1] += 1 else: v2[0] += 1 if wlan[i].payload.dst in dict.keys(): record[dict[wlan[i].payload.dst]] += 1 elif wlan[i].payload.src in dict.keys(): record[dict[wlan[i].payload.src]] += 1 # else: # record[0] += 1 elif ('121.51' in wlan[i].payload.dst) or ('121.51' in wlan[i].payload.src) or \ ('210.41' in wlan[i].payload.dst) or ('210.41' in wlan[i].payload.src): record[4] += 1 elif ('111.231' in wlan[i].payload.dst) or ('111.231' in wlan[i].payload.src): record[1] += 1 print(wlan[i].show()) except: pass # print(hexdump(p)) # 数据处理 for i in range(0, len(timerecord)): timerecord[i].append(record[i]) timesingle[i].append(record[i] - timerecord[i][t]) timetime[i] += min(record[i] - timerecord[i][t], 1) tr.append(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) print('this is the %dth round, sleeping for %f second(s).' % (t + 1, breaktime)) time.sleep(breaktime) # For Debug Use print(timerecord) print(tr) # 作图 global attr page = Page() bar = Bar('报文活跃柱状图') bar.add('按抽样时间分类', attr, timetime, # is_convert=True, is_more_utils=True # 设置最右侧工具栏 ) page.add_chart(bar) bar = Bar('报文请求-时间柱状图') for i in range(0, len(timerecord)): bar.add(attr[i], tr[1:], timesingle[i][1:], is_datazoom_show=True, # is_convert=True, is_more_utils=True # 设置最右侧工具栏 ) page.add_chart(bar) line = Line("访问报文数量-时间折线图") for i in range(0, len(timerecord)): line.add( attr[i], tr, timerecord[i], is_datazoom_show=True, is_fill=True, line_opacity=0.2, area_opacity=0.4 ) page.add_chart(line) pie = Pie('网络-IP类型饼状图', title_pos='left') attr = ['TCP', 'UDP', 'ICMP', 'Other'] pie.add( '', attr, v1, # '':图例名(不使用图例) radius=[50, 75], # 环形内外圆的半径 is_label_show=True, # 是否显示标签 label_text_color=None, # 标签颜色 legend_orient='vertical', # 图例垂直 legend_pos='right' ) attr = ['IP', 'IPv6'] pie.add( '', attr, v2, radius=[15, 35], is_label_show=True, label_text_color=None, legend_orient='vertical', legend_pos='right' ) page.add_chart(pie) # 保存 page.render('./page.html') # 打开 chromepath = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chromepath)) webbrowser.get('chrome').open('page.html')
def score_draw(csv_file): page = Page(csv_file+":评论等级分析") score, date, val, score_list = [], [], [], [] result = {} path = os.path.abspath(os.curdir) csv_file = path + "\\" + csv_file + ".csv" csv_file = csv_file.replace('\\', '\\\\') d = pd.read_csv(csv_file, engine='python', encoding='utf-8')[['score', 'date']].dropna() # 读取CSV转为dataframe格式,并丢弃评论为空的记录 for indexs in d.index: # 一种遍历df行的方法(下面还有第二种,iterrows) score_list.append(tuple(d.loc[indexs].values[:])) # 目前只找到转换为tuple然后统计相同元素个数的方法 #print("有效评分总数量为:",len(score_list), " 条") for i in set(list(score_list)): result[i] = score_list.count(i) # dict类型 ('很差', '2018-04-28'): 55 info = [] for key in result: score= key[0] date = key[1] val = result[key] info.append([score, date, val]) info_new = DataFrame(info) # 将字典转换成为数据框 info_new.columns = ['score', 'date', 'votes'] info_new.sort_values('date', inplace=True) # 按日期升序排列df,便于找最早date和最晚data,方便后面插值 #print("first df", info_new) # 以下代码用于插入空缺的数据,每个日期的评分类型应该有5中,依次遍历判断是否存在,若不存在则往新的df中插入新数值 mark = 0 creat_df = pd.DataFrame(columns = ['score', 'date', 'votes']) # 创建空的dataframe for i in list(info_new['date']): location = info_new[(info_new.date==i)&(info_new.score=="力荐")].index.tolist() if location == []: creat_df.loc[mark] = ["力荐", i, 0] mark += 1 location = info_new[(info_new.date==i)&(info_new.score=="推荐")].index.tolist() if location == []: creat_df.loc[mark] = ["推荐", i, 0] mark += 1 location = info_new[(info_new.date==i)&(info_new.score=="还行")].index.tolist() if location == []: creat_df.loc[mark] = ["还行", i, 0] mark += 1 location = info_new[(info_new.date==i)&(info_new.score=="较差")].index.tolist() if location == []: creat_df.loc[mark] = ["较差", i, 0] mark += 1 location = info_new[(info_new.date==i)&(info_new.score=="很差")].index.tolist() if location == []: creat_df.loc[mark] = ["很差", i, 0] mark += 1 info_new = info_new.append(creat_df.drop_duplicates(), ignore_index=True) score_list = [] info_new.sort_values('date', inplace=True) # 按日期升序排列df,便于找最早date和最晚data,方便后面插值 #print(info_new) for index, row in info_new.iterrows(): # 第二种遍历df的方法 score_list.append([row['date'], row['votes'], row['score']]) tr = ThemeRiver() tr.add(['力荐', '推荐', '还行', '较差', '很差'], score_list, is_label_show=True, is_more_utils=True) page.add_chart(tr) attr, v1, v2, v3, v4, v5 = [], [], [], [], [], [] attr = list(sorted(set(info_new['date']))) bar = Bar() for i in attr: v1.append(int(info_new[(info_new['date']==i)&(info_new['score']=="力荐")]['votes'])) v2.append(int(info_new[(info_new['date']==i)&(info_new['score']=="推荐")]['votes'])) v3.append(int(info_new[(info_new['date']==i)&(info_new['score']=="还行")]['votes'])) v4.append(int(info_new[(info_new['date']==i)&(info_new['score']=="较差")]['votes'])) v5.append(int(info_new[(info_new['date']==i)&(info_new['score']=="很差")]['votes'])) bar.add("力荐", attr, v1, is_stack=True) bar.add("推荐", attr, v2, is_stack=True) bar.add("还行", attr, v3, is_stack=True) bar.add("较差", attr, v4, is_stack=True) bar.add("很差", attr, v5, is_stack=True, is_convert=True, mark_line=["average"], is_more_utils=True) page.add_chart(bar) line = Line() line.add("力荐", attr, v1, is_stack=True) line.add("推荐", attr, v2, is_stack=True) line.add("还行", attr, v3, is_stack=True) line.add("较差", attr, v4, is_stack=True) line.add("很差", attr, v5, is_stack=True, is_convert=False, mark_line=["average"], is_more_utils=True) page.add_chart(line) page.render(csv_file[:-4] + "_日投票量分析汇总.html")
def analyse(self): # 词汇统计——词云 weibo_dir = os.path.split( os.path.realpath(__file__))[0] + os.sep + "weibo" file_path = weibo_dir + os.sep + "%d" % self.user_id + ".txt" f = open(file_path, "r", encoding='utf-8') #创建image文件 image_dir = os.path.split( os.path.realpath(__file__))[0] + os.sep + "image" if not os.path.isdir(image_dir): os.mkdir(image_dir) index = 8 result = '' contentlist = f.readlines() while True: try: content = contentlist[index] #content=content.strip() content = content[2:-1] + " " result = result + content index = index + 6 except IndexError as e: # print("Error: ", e) f.close() w = wordcloud.WordCloud(width=1000, font_path="msyh.ttc", height=700, background_color="white") # 字体为微软雅黑 w.generate(" ".join(jieba.lcut(result))) image_path = image_dir + os.sep + "%d.png" % self.user_id w.to_file(image_path) break #发布数统计——条形图 weibo_dir = os.path.split( os.path.realpath(__file__))[0] + os.sep + "weibo" file_path = weibo_dir + os.sep + "%d_2" % self.user_id + ".txt" f = open(file_path, "r", encoding='utf-8') # 创建image文件 image_dir = os.path.split( os.path.realpath(__file__))[0] + os.sep + "image" if not os.path.isdir(image_dir): os.mkdir(image_dir) index = -1 year_list = [] month_list = [] number_list = [] sum_number_list = [] contentlist = f.readlines() lens = len(contentlist) i = 0 while i < lens - 1: if i == 0 or contentlist[i] == '\n': if i != 0: i = i + 1 year_list.append(contentlist[i][:-1]) # 年份 # 月份和发布数 month_list.append([]) number_list.append([]) index = index + 1 else: temp_list = contentlist[i].split(": ") if temp_list[0] != "总计": month_list[index].append(temp_list[0]) number_list[index].append(temp_list[1][:-1]) else: sum_number_list.append(temp_list[1][:-1]) i = i + 1 year_lens = len(year_list) bar_list = [] page = Page(page_title=(self.username + "的微博数统计")) for j in range(0, year_lens): bar = Bar(year_list[j]) bar.add("年发布数", month_list[j], number_list[j], mark_point=["max", "min"], mark_line=["average"]) bar_list.append(bar) bar = Bar(year_list[year_lens - 1] + "-" + year_list[0]) re_year_list = year_list[::-1] re_sum_number_list = sum_number_list[::-1] bar.add("总发布数", re_year_list, re_sum_number_list, mark_line=["average"], mark_point=["max", "min"]) bar_list.append(bar) bar_lens = len(bar_list) for k in range(0, bar_lens): page.add(bar_list[k]) html_path = image_dir + os.sep + "%d.html" % self.user_id page.render(html_path)
# grid.add(line,grid_right="55%") # grid.add(line1,grid_left="55%") page.add_chart(grid) spot_line(10108,'今日头条') spot_line(10044,'聚效') spot_line(10169,'哔哩哔哩') spot_line(10167,'咪咕') spot_line(10008,'优酷') spot_line(10097,'陌陌') spot_line(10010,'新浪') spot_line(10048,'新浪微博移动端') spot_line(10004,'淘宝') spot_line(10009,'百度') page.render(path='F:/test.html') #%% TOP客户消耗 def user_table(cnt,name): if cnt: querybody = { "begin_time": date2ts(begin_time), "end_time": date2ts(end_time), "timeout": 300000, "keys": [ "user_id","date" ], "dims": [], "query_type": "default", "metrics": [ "cost_r", ],
def test_more(): page = Page() # line line = Line("折线图示例") line.add( "最高气温", WEEK, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], ) line.add( "最低气温", WEEK, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], ) # pie v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图-圆环图示例", title_pos="center") pie.add( "", CLOTHES, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", ) page.add([line, pie]) # kline v1 = [ [2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03], [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07], [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82], [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78], [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63], [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65], [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14], [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02], [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96], [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33], [2255.77, 2270.28, 2253.31, 2276.22], ] kline = Kline("K 线图示例") kline.add( "日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, is_datazoom_show=True, ) page.add(kline) # radar schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000), ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] radar = Radar("雷达图示例") radar.config(schema) radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True) radar.add( "实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode="single", ) page.add(radar) # scatter3d import random data = [ [ random.randint(0, 100), random.randint(0, 100), random.randint(0, 100), ] for _ in range(80) ] scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600) scatter3D.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR) page.add(scatter3D) # wordcloud name = [ "Sam S Club", "Macys", "Amy Schumer", "Jurassic World", "Charter Communications", "Chick Fil A", "Planet Fitness", "Pitch Perfect", "Express", "Home", "Johnny Depp", "Lena Dunham", "Lewis Hamilton", "KXAN", "Mary Ellen Mark", "Farrah Abraham", "Rita Ora", "Serena Williams", "NCAA baseball tournament", "Point Break", ] value = [ 10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265, ] wordcloud = WordCloud(width=1300, height=620) wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66) page.add(wordcloud) # liquid liquid = Liquid("水球图示例") liquid.add("Liquid", [0.6]) page.add(liquid) assert len(page) == 7 assert isinstance(page[0], Line) assert ( ("echarts" in page.js_dependencies) or ("echarts.min" in page.js_dependencies) ) page.render()
bar.add("城市", attr, v1, is_stack=True, xaxis_rotate=30, yaxix_min=4.2, xaxis_interval=0, is_splitline_show=False) page.add(bar) overlap = Overlap() overlap.add(bar) overlap.add(line, yaxis_index=1, is_add_yaxis=True) #overlap.render('主要城市评论数_平均分.html') page.add(overlap) page.render("movie_analysis.html") #词云分析 #分词 comment = jieba.cut(str(data['comment']), cut_all=False) wl_space_split = " ".join(comment) #导入背景图 backgroud_Image = plt.imread('C_73.png') stopwords = STOPWORDS.copy() #print("STOPWORDS.copy()",help(STOPWORDS.copy())) wc = WordCloud(width=1024, height=768, background_color='white', mask=backgroud_Image,