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 test_page(): page = Page() line = Line("折线图示例") line.chart_id = "id_my_cell_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", width="600px") 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, create_a_bar(TITLE)]) # Start render and test html = page._repr_html_() # Test base html structure assert html.count("<script>") == html.count("</script>") == 2 assert html.count("<div") == html.count("</div>") == 3 assert html.count("require.config") == html.count("function(echarts)") == 1 # Test some chart attributes json_encoded_title = json.dumps(TITLE) assert json_encoded_title in html assert "nbextensions/echarts" in html # default jshost assert html.count("height:400px") == 3 assert html.count("width:600px") == 1 assert html.count("width:800px") == 2 assert html.count("id_my_cell_line") == 6
def create_three(): page = Page(page_title=TEST_PAGE_TITLE) # bar v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True) page.add(bar) # 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) # guangdong value = [20, 190, 253, 77, 65] attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市'] map = Map("广东地图示例", width=1200, height=600) map.add("", attr, value, maptype='广东', is_visualmap=True, visual_text_color='#000') page.add(map) return page
def show_backtesting_indicator(cls, event): indicator_dict = {} indicator_dict = collections.OrderedDict() # (1)基准净值 benchmark_net_asset_value = cls().get_benchmark_net_asset_value(event) # print(benchmark_net_asset_value, "benchmark_net_asset_value" * 3) # (2)策略净值 strategy_net_asset_value = cls().get_strategy_net_asset_value() # print(strategy_net_asset_value, "strategy_net_asset_value") # (3)基准年化收益率 benchmark_year_yield = cls().get_year_yield(benchmark_net_asset_value) # (4)策略年化收益率 strategy_year_yield = cls().get_year_yield(strategy_net_asset_value) # print(benchmark_year_yield, strategy_year_yield) # (5)beta beta = cls().get_beta(benchmark_net_asset_value, strategy_net_asset_value) # print(beta) indicator_dict["beta"] = beta # (6)alpha alpha = cls().get_alpha(benchmark_year_yield, strategy_year_yield, beta) # print(alpha) indicator_dict["alpha"] = alpha # (7)volatility volatility = cls().get_volatility(strategy_net_asset_value) # print(volatility) indicator_dict["volatility"] = volatility # (8)sharpe sharpe = cls().get_sharp(strategy_year_yield, volatility) # print(sharpe) indicator_dict["sharpe"] = sharpe # (9)downside_risk downside_risk = cls().get_downside_risk(strategy_year_yield) # print(downside_risk) indicator_dict["downside_risk"] = downside_risk # (10)sortino_ratio sortino_ratio = cls().get_sortino_ratio(strategy_year_yield, downside_risk) # print(sortino_ratio) indicator_dict["sortino_ratio"] = sortino_ratio # (11)tracking_error tracking_error = cls().get_tracking_error(benchmark_net_asset_value, strategy_net_asset_value) # print(tracking_error) indicator_dict["tracking_error"] = tracking_error # (12)information_ratio information_ratio = cls().get_information_ratio(benchmark_year_yield, strategy_year_yield, tracking_error) # print(information_ratio) indicator_dict["information_ratio"] = information_ratio # (13)max_drawdown max_drawdown = cls().get_max_drawdown(strategy_net_asset_value) # print(max_drawdown) indicator_dict["max_drawdown"] = max_drawdown # 展示到html period = event.event_data_dict["strategy"].period if period == Period.DAILY.value: timetag_date = [millisecond_to_date(millisecond=i, format="%Y-%m-%d") for i in Environment.benchmark_index] else: timetag_date = [millisecond_to_date(millisecond=i, format="%Y-%m-%d %H:%M:%S") for i in Environment.benchmark_index] page = Page("strategy backtesting indicator") line_net_asset_value = Line("net_asset_value", width=1300, height=400, title_pos="8%") line_net_asset_value.add("benchmark_net_asset_value", timetag_date, [round(i, 4) for i in benchmark_net_asset_value], tooltip_tragger="axis", legend_top="3%", is_datazoom_show=True) line_net_asset_value.add("strategy_net_asset_value", timetag_date, [round(i, 4) for i in strategy_net_asset_value], tooltip_tragger="axis", legend_top="3%", is_datazoom_show=True) page.add(line_net_asset_value) line_year_yield = Line("year_yield", width=1300, height=400, title_pos="8%") line_year_yield.add("benchmark_year_yield", timetag_date, [round(i, 4) for i in benchmark_year_yield], tooltip_tragger="axis", legend_top="3%", is_datazoom_show=True) line_year_yield.add("strategy_year_yield", timetag_date, [round(i, 4) for i in strategy_year_yield], tooltip_tragger="axis", legend_top="3%", is_datazoom_show=True) page.add(line_year_yield) for indicator_name, indicator in indicator_dict.items(): cls().add_to_page(page, indicator, indicator_name, timetag_date) # print(indicator_name) millisecond_timetag = str(int(time.time()) * 1000) page.render(path=sys.argv[0][sys.argv[0].rfind(os.sep) + 1:][ :-3] + "_" + "strategy backtesting indicator" + millisecond_timetag + ".html") # 生成本地 HTML 文件
""" 1.从2010年到2017年之间最受欢迎的男女生英文名,画出男女生各前10名的年份-数量图 """ #男生 top10_boy=data.loc[(data['Year'].isin(list(range(2010,2018))))&(data['Gender']=='M'),:].groupby('Name').Count.sum().nlargest(10) boy_total=data.loc[(data['Year'].isin(list(range(2010,2018))))&(data['Gender']=='M'),:].groupby('Name').Count.sum().sum() #print(boy_total) bname=list(top10_boy.index) bvalue=list(top10_boy.values) wordcloud1=WordCloud("2010年以来最受欢迎的男生名Top10",width=1000,height=500,background_color='#f2eada') wordcloud1.add("",bname,bvalue,word_size_range=[20,100],shape='dimand') page.add(wordcloud1) #wordcloud.render() data_top10_boy=data.loc[(data['Year'].isin(list(range(2010,2018))))&(data['Gender']=='M')&(data['Name']).isin(list(top10_boy.index)),:] #print(data_top15_boy) #sns绘图 sns.set(font_scale=2) #标题大小 g1 = sns.FacetGrid(data_top10_boy, col="Name", col_wrap=4) #列名为Name,一行四个 t1=g1.map(plt.plot, "Year", "Count",color="b",marker="o") #绘图,横轴为Year,纵轴为Count plt.show(t1) #女生 top10_girl = data.loc[(data['Year'].isin(list(range(2010,2018)))) & (data['Gender'] == 'F'), :].groupby('Name').Count.sum().nlargest(10) list(data.loc[(data['Year'].isin(list(range(2010,2018)))) & (data['Gender'] == 'F'), :].groupby('Name').Count.sum().nlargest(30).index) gname = list(top10_girl.index)
is_smooth=True) return line week_report = open('week_report', 'rb') week_report_str = week_report.read().decode() week_report_list = week_report_str.split('FROM_UNIXTIME(clock) value_max') tips_list = [ "支付核心 CPU", "支付核心 内存", "支付核心 磁盘", "门户/认证中心 CPU", "门户/认证中心 内存", "门户/认证中心网络", "门户/认证中心磁盘", "核心交换机CPU", "核心交换机内存", "移动网络流量", "电信网络流量", "人保金服到集团核心网RT1", "人保金服到集团核心网RT2", "人保金服到华夏银行RT1", "人保金服到华夏银行RT2" ] unit_list = [ "%", "MB", "GB", "%", "MB", "Kbps", "GB", "%", "%", "Kbps", "Kbps", "Kbps", "Kbps", "bps", "Kbps" ] level_list = [ 0.01, 0.000001, 0.000000001, 0.01, 0.000001, BPS_2_KBPS, 0.000000001, 1, 1, BPS_2_KBPS, BPS_2_KBPS, BPS_2_KBPS, BPS_2_KBPS, 1, BPS_2_KBPS ] page = Page() count = 0 list_count = 1 for tips in tips_list: line = make_line(week_report_list[list_count:list_count + 2], tips, unit_list[count], level_list[count], count) count += 1 list_count += 2 page.add(line) page.render()
ma_30 = L_ine(date, close, 30) #日K线 kline = K_line(date, v1, "比特币历史行情-MA以及交易量") #交易量 bar = Volume_bar(date, volume) overlap = Overlap(width=1500, height=600) overlap.add(kline) overlap.add(ma_5) overlap.add(ma_10) overlap.add(ma_20) overlap.add(ma_30) overlap.add(bar, is_add_yaxis=True, yaxis_index=1) page = Page() # 第一个图表 page.add(overlap) #MACD指标 #DIF=MA(12)-MA(26) a=12,b=16 #EDA=9日EMA c=9 #macd=DIF-EDA bar def DIF(a, b): dif = [] ma_a = MA(close, a) ma_b = MA(close, b) #让ma_a和ma_b具有相同维度 ma_a = ma_a[b - a:] for i in range(len(ma_a)): dif.append(ma_a[i] - ma_b[i])
def CreateCharts(): page = Page() app = xw.App(visible=False, add_book=False) app.display_alerts = False app.screen_updating = False book = app.books.open(filepath) sheet = book.sheets['sheet1'] _list1 = [] _list2 = [] _list3 = [] _list4 = [] _list5 = [] # 从 excel 中获取数据 cells1 = sheet.range('F3:K3').value # 第 1 支球队 cells2 = sheet.range('F4:K4').value # 第 2 支球队 cells3 = sheet.range('F5:K5').value # 第 3 支球队 cells4 = sheet.range('F6:K6').value # 第 4 支球队 cells5 = sheet.range('F7:K7').value # 第 5 支球队 # print(data1) for cell1,cell2,cell3,cell4,cell5 in zip(cells1,cells2,cells3,cells4,cells5): _list1.append(cell1) _list2.append(cell2) _list3.append(cell3) _list4.append(cell4) _list5.append(cell5) v1 = [_list1] v2 = [_list2] v3 = [_list3] v4 = [_list4] v5 = [_list5] chart = Radar("进攻属性") schema = [ ("进球", 15), ("射门", 20), ("射正", 9), ("绝佳机会", 20), ("机会把握率", 70), ("过人", 16), # ("被侵犯", 18), # ("越位", 5), ] chart.config(schema) chart.add("利物浦", v1) chart.add("诺维奇", v2) chart.add("曼城", v3) chart.add("西汉姆联", v4) chart.add("伯恩利", v5) page.add(chart) # 玫瑰图 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v2 = [19, 21, 32, 20, 20, 33] chart = Pie("饼图-玫瑰图示例", title_pos='center') chart.add("商品A", attr, v2, is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True) page.add(chart) # 雷达图 schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] v3 = [[3000, 9000, 27890, 33000, 43098, 18000]] v4 = [[3890, 12098, 29022, 32000, 41000, 20000]] chart = Radar("雷达图-默认指示器") chart.config(schema) chart.add("预算分配", v1) chart.add("实际开销", v2) chart.add("ddd", v3) chart.add("fff", v4) page.add(chart) app.kill() return page
def create_charts(): page = Page() style = Style(width=1100, height=600) df = pd.read_csv('./处置部门关联规则.csv') x_list = list(df['lhs'].values) y_list = list(df['rhs'].values) sup = list(df['sup_lhs']) conf = list(df['conf']) nodes = [] links = [] all_list = [] all_list.extend(x_list) all_list.extend(y_list) all_list = list(set(all_list)) for i in range(len(all_list)): nodes.append({ "name": all_list[i], "symbolSize": 10, "label": { "normal": { "show": "True" } } }) for j in range(len(x_list)): links.append({"source": x_list[j], "target": y_list[j]}) # print(nodes) # print(links) chart = Graph("关联规则", **style.init_style) chart.add("", nodes, links, label_pos="right", graph_repulsion=1000, is_legend_show=False, line_curve=0.2, label_text_color=None) page.add(chart) comm_name = [ '竹坑社区', '沙田社区', '龙田社区', '秀新社区', '金沙社区', '碧岭社区', '老坑社区', '和平社区', '六和社区', '六联社区', '坪山社区' ] nodes = [] links = [] categories = [] for name in comm_name: # print(name) df = pd.read_csv('./' + name + '.csv') x_list = list(df['lhs'].values) y_list = list(df['rhs'].values) all_list = [] all_list.extend(x_list) all_list.extend(y_list) all_list = list(set(all_list)) for i in range(len(all_list)): # print(all_list[i]) nodes.append({ "name": name + all_list[i], "symbolSize": 10, "draggable": "False", "category": name, "label": { "normal": { "show": "True" } } }) categories.append({"name": name}) for j in range(len(x_list)): links.append({ "source": name + x_list[j], "target": name + y_list[j] }) chart = Graph("", **style.init_style) chart.add("", nodes, links, categories, label_pos="right", graph_repulsion=1000, is_legend_show=True, line_curve=0.2, label_text_color=None) page.add(chart) return page
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 plotClassInfo(): list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("上海")] [list_address.append(i[1]) for i in foodClassinif("上海")] print(list_address) print(list_sum) page = Page() pie1 = Pie("上海商铺集中区域", title_pos='center') pie1.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar1 = Bar("上海商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar1.add("上海", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("北京")] [list_address.append(i[1]) for i in foodClassinif("北京")] print(list_address) print(list_sum) pie2 = Pie("北京商铺集中区域", title_pos='center') pie2.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar2 = Bar("北京商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar2.add("北京", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("广州")] [list_address.append(i[1]) for i in foodClassinif("广州")] print(list_address) print(list_sum) pie3 = Pie("广州商铺集中区域", title_pos='center') pie3.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar3 = Bar("广州商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar3.add("广州", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("深圳")] [list_address.append(i[1]) for i in foodClassinif("深圳")] print(list_address) print(list_sum) pie4 = Pie("深圳商铺集中区域", title_pos='center') pie4.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar4 = Bar("深圳商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar4.add("深圳", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("天津")] [list_address.append(i[1]) for i in foodClassinif("天津")] print(list_address) print(list_sum) pie5 = Pie("天津商铺集中区域", title_pos='center') pie5.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar5 = Bar("天津商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar5.add("天津", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("杭州")] [list_address.append(i[1]) for i in foodClassinif("杭州")] print(list_address) print(list_sum) pie6 = Pie("杭州商铺集中区域", title_pos='center') pie6.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar6 = Bar("杭州商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar6.add("杭州", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("南京")] [list_address.append(i[1]) for i in foodClassinif("南京")] print(list_address) print(list_sum) pie7 = Pie("南京商铺集中区域", title_pos='center') pie7.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar7 = Bar("南京商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar7.add("南京", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("苏州")] [list_address.append(i[1]) for i in foodClassinif("苏州")] print(list_address) print(list_sum) pie8 = Pie("苏州商铺集中区域", title_pos='center') pie8.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar8 = Bar("苏州商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar8.add("苏州", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("成都")] [list_address.append(i[1]) for i in foodClassinif("成都")] print(list_address) print(list_sum) pie9 = Pie("成都商铺集中区域", title_pos='center') pie9.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar9 = Bar("成都商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar9.add("成都", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("武汉")] [list_address.append(i[1]) for i in foodClassinif("武汉")] print(list_address) print(list_sum) pie10 = Pie("武汉商铺集中区域", title_pos='center') pie10.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar10 = Bar("武汉商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar10.add("武汉", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("重庆")] [list_address.append(i[1]) for i in foodClassinif("重庆")] print(list_address) print(list_sum) pie11 = Pie("重庆商铺集中区域", title_pos='center') pie11.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar11 = Bar("重庆商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar11.add("重庆", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") list_address = [] list_sum = [] [list_sum.append(i[0]) for i in foodClassinif("西安")] [list_address.append(i[1]) for i in foodClassinif("西安")] print(list_address) print(list_sum) pie12 = Pie("西安商铺集中区域", title_pos='center') pie12.add("", list_address, list_sum, radius=[30, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='auto', is_legend_show=False) bar12 = Bar("西安商铺集中区域", "数据来源于大众点评TOP100", title_pos='center') bar12.add("西安", list_address, list_sum, mark_point=["max", "min"], legend_pos="right") page.add(pie1) page.add(bar1) page.add(pie2) page.add(bar2) page.add(pie3) page.add(bar3) page.add(pie4) page.add(bar4) page.add(pie5) page.add(bar5) page.add(pie6) page.add(bar6) page.add(pie7) page.add(bar7) page.add(pie8) page.add(bar8) page.add(pie9) page.add(bar9) page.add(pie10) page.add(bar10) page.add(pie11) page.add(bar11) page.add(pie12) page.add(bar12) page.render("商铺集中区域.html")
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 create_charts(): page = Page() data = [("海门", 9), ("鄂尔多斯", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15), ("赤峰", 16), ("青岛", 18), ("乳山", 18), ("金昌", 19), ("泉州", 21), ("莱西", 21), ("日照", 21), ("胶南", 22), ("南通", 23), ("拉萨", 24), ("云浮", 24), ("梅州", 25), ("文登", 25), ("上海", 25), ("攀枝花", 25), ("威海", 25), ("承德", 25), ("厦门", 26), ("汕尾", 26), ("潮州", 26), ("丹东", 27), ("太仓", 27), ("曲靖", 27), ("烟台", 28), ("福州", 29), ("瓦房店", 30), ("即墨", 30), ("抚顺", 31), ("玉溪", 31), ("张家口", 31), ("阳泉", 31), ("莱州", 32), ("湖州", 32), ("汕头", 32), ("昆山", 33), ("宁波", 33), ("湛江", 33), ("揭阳", 34), ("荣成", 34), ("连云港", 35), ("葫芦岛", 35), ("常熟", 36), ("东莞", 36), ("河源", 36), ("淮安", 36), ("泰州", 36), ("南宁", 37), ("营口", 37), ("惠州", 37), ("江阴", 37), ("蓬莱", 37), ("韶关", 38), ("嘉峪关", 38), ("广州", 38), ("延安", 38), ("太原", 39), ("清远", 39), ("中山", 39), ("昆明", 39), ("寿光", 40), ("盘锦", 40), ("长治", 41), ("深圳", 41), ("珠海", 42), ("宿迁", 43), ("咸阳", 43), ("铜川", 44), ("平度", 44), ("佛山", 44), ("海口", 44), ("江门", 45), ("章丘", 45), ("肇庆", 46), ("大连", 47), ("临汾", 47), ("吴江", 47), ("石嘴山", 49), ("沈阳", 50), ("苏州", 50), ("茂名", 50), ("嘉兴", 51), ("长春", 51), ("胶州", 52), ("银川", 52), ("张家港", 52), ("三门峡", 53), ("锦州", 54), ("南昌", 54), ("柳州", 54), ("三亚", 54), ("自贡", 56), ("吉林", 56), ("阳江", 57), ("泸州", 57), ("西宁", 57), ("宜宾", 58), ("呼和浩特", 58), ("成都", 58), ("大同", 58), ("镇江", 59), ("桂林", 59), ("张家界", 59), ("宜兴", 59), ("北海", 60), ("西安", 61), ("金坛", 62), ("东营", 62), ("牡丹江", 63), ("遵义", 63), ("绍兴", 63), ("扬州", 64), ("常州", 64), ("潍坊", 65), ("重庆", 66), ("台州", 67), ("南京", 67), ("滨州", 70), ("贵阳", 71), ("无锡", 71), ("本溪", 71), ("克拉玛依", 72), ("渭南", 72), ("马鞍山", 72), ("宝鸡", 72), ("焦作", 75), ("句容", 75), ("北京", 79), ("徐州", 79), ("衡水", 80), ("包头", 80), ("绵阳", 80), ("乌鲁木齐", 84), ("枣庄", 84), ("杭州", 84), ("淄博", 85), ("鞍山", 86), ("溧阳", 86), ("库尔勒", 86), ("安阳", 90), ("开封", 90), ("济南", 92), ("德阳", 93), ("温州", 95), ("九江", 96), ("邯郸", 98), ("临安", 99), ("兰州", 99), ("沧州", 100), ("临沂", 103), ("南充", 104), ("天津", 105), ("富阳", 106), ("泰安", 112), ("诸暨", 112), ("郑州", 113), ("哈尔滨", 114), ("聊城", 116), ("芜湖", 117), ("唐山", 119), ("平顶山", 119), ("邢台", 119), ("德州", 120), ("济宁", 120), ("荆州", 127), ("宜昌", 130), ("义乌", 132), ("丽水", 133), ("洛阳", 134), ("秦皇岛", 136), ("株洲", 143), ("石家庄", 147), ("莱芜", 148), ("常德", 152), ("保定", 153), ("湘潭", 154), ("金华", 157), ("岳阳", 169), ("长沙", 175), ("衢州", 177), ("廊坊", 193), ("菏泽", 194), ("合肥", 229), ("武汉", 273), ("大庆", 279)] style = Style(title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59') chart = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, visual_range=[0, 200], visual_text_color="#fff", is_legend_show=False, symbol_size=15, is_visualmap=True, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right') page.add(chart) chart = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, type="heatmap", is_visualmap=True, visual_range=[0, 200], visual_text_color='#fff', is_legend_show=False) page.add(chart) data = [('汕头市', 50), ('汕尾市', 60), ('揭阳市', 35), ('阳江市', 44), ('肇庆市', 72)] chart = Geo("广东地理坐标系", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, maptype='广东', type="effectScatter", is_random=True, effect_scale=5, is_legend_show=False, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right') page.add(chart) data = [('澄海区', 30), ('南澳县', 40), ('龙湖区', 50), ('金平区', 60)] chart = Geo("汕头地理坐标系", **style.init_style) attr, value = chart.cast(data) chart.add("", attr, value, maptype="汕头", is_visualmap=True, is_legend_show=False, tooltip_formatter='{b}', label_emphasis_textsize=15, label_emphasis_pos='right') page.add(chart) return page
def Page_hello(): date, open, close, low, high, volume = Import() v1 = V1(open, close, low, high) #5日均线 ma_5 = L_ine(date, close, 5) #10日均线 ma_10 = L_ine(date, close, 10) #20日均线 ma_20 = L_ine(date, close, 20) #5日均线 ma_30 = L_ine(date, close, 30) #日K线 kline = K_line(date, v1, "比特币历史行情-MA以及交易量") #交易量 bar = Volume_bar(date, volume) overlap = Overlap(width=1500, height=600) overlap.add(kline) overlap.add(ma_5) overlap.add(ma_10) overlap.add(ma_20) overlap.add(ma_30) overlap.add(bar, is_add_yaxis=True, yaxis_index=1) page = Page() # 第一个图表 page.add(overlap) kline = K_line(date, v1, "比特币macd指标") overlap_uper = Overlap() overlap_uper.add(kline) overlap_uper.add(L_ine(date, close, 12)) overlap_uper.add(L_ine(date, close, 26)) #dif曲线 grid 下面的图 dif_line = DIF_Line(date, 12, 26, close) eda_line = EDA_Line(date, 12, 26, 9, close) macd_bar = MACD_Bar(date, 12, 26, 9, close) overlap_down = Overlap() overlap_down.add(dif_line) overlap_down.add(eda_line) overlap_down.add(macd_bar) grid = Grid(width=1500, height=600) grid.add(overlap_down, grid_top="60%") grid.add(overlap_uper, grid_bottom="60%") #第二幅画 page.add(grid) #增加RSI指标 #日k线图 kline = K_line(date, v1, "比特币RSI指标") overlap_uper = Overlap() overlap_uper.add(kline) rsi_line = RSI_Line(close, date, 14) overlap_down = Overlap() overlap_down.add(rsi_line) grid = Grid(width=1500, height=600) grid.add(overlap_down, grid_top="60%") grid.add(overlap_uper, grid_bottom="60%") #第三幅画 page.add(grid) #####mack stratege # 寻找合适的slow_ma kline = K_line(date, v1, "比特币macd策略回测平台") overlap = Overlap(width=1500, height=600) overlap.add(kline) for i in range(20, 50): macd_strategy_buyonly_line = MACD_strategy_buyonly_Line( 12, i, 9, close, date) overlap.add(macd_strategy_buyonly_line) # for i in range(1,30): # macd_strategy_buyonly_line=MACD_strategy_buyonly_Line(i,36,9,close,date) # overlap.add(macd_strategy_buyonly_line) #第四幅画-回测平台 page.add(overlap) kline = K_line(date, v1, "比特币macd策略回测平台") overlap = Overlap(width=1500, height=600) overlap.add(kline) # for i in range(20,50): # # macd_strategy_buyonly_line=MACD_strategy_buyonly_Line(12,i,9,close,date) # overlap.add(macd_strategy_buyonly_line) for i in range(1, 30): macd_strategy_buyonly_line = MACD_strategy_buyonly_Line( i, 36, 9, close, date) overlap.add(macd_strategy_buyonly_line) #第四幅画-回测平台 page.add(overlap) kline = K_line(date, v1, "比特币macd策略回测平台") overlap = Overlap(width=1500, height=600) overlap.add(kline) # for i in range(20,50): # # macd_strategy_buyonly_line=MACD_strategy_buyonly_Line(12,i,9,close,date) # overlap.add(macd_strategy_buyonly_line) for i in range(1, 30): macd_strategy_buyonly_line = MACD_strategy_buyonly_Line( 3, 36, i, close, date) overlap.add(macd_strategy_buyonly_line) #第四幅画-回测平台 page.add(overlap) #####mack stratege # 根据历史得到的 最佳macd 参数 kline = K_line(date, v1, "比特币macd策略最佳参数与默认参数对比效果") overlap = Overlap(width=1500, height=600) overlap.add(kline) macd_strategy_buyonly_line = MACD_strategy_buyonly_Line( 3, 36, 9, close, date) overlap.add(macd_strategy_buyonly_line) macd_strategy_buyonly_line = MACD_strategy_buyonly_Line( 12, 26, 9, close, date) overlap.add(macd_strategy_buyonly_line) #第四幅画-回测平台 page.add(overlap) #####基本面分析 # 梅特卡夫定律 #Value∝n^2 Value∝nln(n) v2 = V1(Log(open), Log(close), Log(low), Log(high)) kline = K_line(date, v2, "比特币基本面分析之梅特卡夫定律") upper_Bound = Upper_Bound(-16.5, 1) lower_Bound = Lower_Bound(-11, 1) overlap = Overlap(width=1500, height=600) overlap.add(kline) overlap.add(lower_Bound) overlap.add(upper_Bound) # page.add(overlap) #基本面分析之对数回归 #假设 每次投机产生的指数上涨有规律的 根据对数坐标系发掘这些规律 #预计 周期更加漫长 涨幅更加有限 量化找到其规律 趋势面前 一切都是徒劳的 顺势而为 #基本面分析之对数回归 #假设 每次投机产生的指数上涨有规律的 根据对数坐标系发掘这些规律 #预计 周期更加漫长 涨幅更加有限 量化找到其规律 趋势面前 一切都是徒劳的 顺势而为 #构造横坐标 x_axis = [] for i in range(len(date)): x_axis.append(i) #构造纵坐标 close_log = Log(close) close_log_ma5, kline_log_ma5 = Kline_log_ma(5, x_axis, close) close_log_ma100, kline_log_ma100 = Kline_log_ma(100, x_axis, close) overlap = Overlap(width=1500, height=600) #二次多项式拟合 a1, b1, c1, curve_line_QP1 = Curve_Line_num(1, 101, 324, close_log, 101, 100) a2, b2, c2, curve_line_QP2 = Curve_Line_num(2, 324, 1232, close_log, 200, 200) a3, b3, c3, curve_line_QP3 = Curve_Line_num(3, 1232, 2709, close_log, 500, 500) a4, b4, c4, curve_line_QP4 = Curve_Line_num(4, 2709, 3073, close_log, 1000, 2000) predicthigh_line = PredictLow_Line([325, 1229, 2709], [3.38, 7.00, 9.85], 5000) predictlow_line = PredictHigh_Line([b1, b2, b3], [c1, c2, c3], 5000) kline = K_line(x_axis, v2, "比特币基本面分析之二次多项式回归") overlap.add(predictlow_line) overlap.add(predicthigh_line) #overlap.add(predicttrend_line) overlap.add(kline) # overlap.add(kline_log_ma5) # overlap.add(kline_log_ma100) overlap.add(curve_line_QP1) overlap.add(curve_line_QP2) overlap.add(curve_line_QP3) overlap.add(curve_line_QP4) #tomorror mission #对数拟合 page.add(overlap) overlap = Overlap(width=1500, height=600) predict_date_line = Predict_date(date, close, 3106, 4545) overlap.add(predict_date_line) page.add(overlap) return page
def draw_danmu_num(time_data, num_data, sum_data, avg_data, pos_data, neg_data): page = Page() bar = Bar("弹幕数量分布图", "2020-01-27", title_color='black', title_pos='center', width=1000) bar.add("弹幕数量", time_data, num_data, mark_line=['average'], mark_point=['max', 'min'], legend_pos='right', is_more_utils=True) page.add(bar) bar = Bar("弹幕情感均值分布图", "2020-01-27", title_color='black', title_pos='center', width=1000) bar.add("弹幕情感均值", time_data, avg_data, mark_line=['average'], mark_point=['max', 'min'], legend_pos='right', is_more_utils=True) page.add(bar) bar = Bar("弹幕情感总和分布图", "2020-01-27", title_color='black', title_pos='center', width=1000) bar.add("弹幕情感总和", time_data, sum_data, mark_line=['average'], mark_point=['max', 'min'], legend_pos='right', is_more_utils=True) page.add(bar) bar = Bar("弹幕正面情感总和分布图", "2020-01-27", title_color='black', title_pos='center', width=1000) bar.add("弹幕正面情感总和", time_data, pos_data, mark_line=['average'], mark_point=['max', 'min'], legend_pos='right', is_more_utils=True) page.add(bar) bar = Bar("弹幕负面情感总和分布图", "2020-01-27", title_color='black', title_pos='center', width=1000) bar.add("弹幕负面情感总和", time_data, neg_data, mark_line=['average'], yaxis_max=350, mark_point=['max', 'min'], legend_pos='right', is_more_utils=True) page.add(bar) page.render("new_每30s弹幕数据.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")
# 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
$ pip install echarts-china-counties-pypkg $ pip install echarts-china-misc-pypkg """ from pyecharts import Page, Bar page = Page() attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图数据堆叠示例") #is_stack 数据叠堆 bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) import random page.add(bar) attr = ["{}天".format(i) for i in range(30)] v1 = [random.randint(1, 30) for _ in range(30)] bar = Bar("Bar - datazoom - slider 示例") #is_datazoom_show 显示下方可调整的日期 bar.add("", attr, v1, is_label_show=True, mark_line=['average'], mark_point=['max', 'min'], is_datazoom_show=True) page.add(bar)
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)
def create_charts(): page = Page() style = Style( width=WIDTH, height=HEIGHT ) performance = Line("Performance Summary", **style.init_style) us_bd = CustomBusinessDay(calendar=USFederalHolidayCalendar()) dates = pd.date_range('2017-10-26', periods=100, freq=us_bd) self_record = [0.135, 0.155, 0.108, 0.094, -0.052, 0.1, 0.16, -0.166, 0.198, 0.055, -0.04, 0.024, 0.077, 0.148, 0.035, -0.068, -0.108, -0.092, -0.016, 0.142, - 0.034, -0.077, -0.185, 0.077, -0.158, 0.021, -0.111, -0.1, 0.079, 0.092, 0.119, -0.139, -0.104, 0.045, - 0.195, 0.053, -0.078, -0.046, -0.192, -0.05, 0.159, -0.058, 0.094, -0.072, 0.005, 0.057, 0.173, - 0.077, -0.164, 0.071, -0.088, 0.007, 0.12, -0.07, -0.091, 0.059, 0.177, 0.107, -0.122, 0.005, 0.09, - 0.108, -0.102, -0.006, -0.07, 0.07, -0.111, -0.164, -0.051, -0.129, -0.151, -0.192, - 0.083, 0.144, 0.132, 0.013, 0.09, 0.123, 0.187, -0.12, 0.102, -0.064, -0.014, -0.19, -0.093, -0.199, - 0.155, 0.078, -0.05, -0.123, 0.067, 0.186, -0.04, -0.019, -0.146, -0.007, 0.167, -0.082, -0.17, 0.055] mirror_record = [0.079, 0.024, 0.073, 0.105, 0.034, 0.085, 0.07, 0.091, 0.084, 0.053, 0.14, 0.195, 0.2, 0.195, 0.068, 0.212, 0.15, 0.071, 0.138, 0.1, 0.256, 0.288, 0.292, 0.28, 0.323, 0.308, 0.252, 0.324, 0.275, 0.197, 0.369, 0.222, 0.336, 0.315, 0.393, 0.36, 0.362, 0.416, 0.324, 0.435, 0.32, 0.36, 0.4, 0.361, 0.505, 0.407, 0.559, 0.503, 0.473, 0.402, 0.471, 0.472, 0.491, 0.484, 0.543, 0.584, 0.656, 0.628, 0.555, 0.635, 0.581, 0.525, 0.597, 0.603, 0.584, 0.679, 0.617, 0.65, 0.701, 0.61, 0.684, 0.709, 0.671, 0.677, 0.81, 0.73, 0.769, 0.698, 0.788, 0.745, 0.785, 0.732, 0.808, 0.922, 0.797, 0.905, 0.811, 0.969, 0.834, 0.928, 0.812, 0.947, 0.961, 0.873, 0.844, 1.009, 0.93, 1.039, 1.022, 0.968] overall = [0.214, 0.179, 0.181, 0.199, -0.018, 0.185, 0.23, -0.075, 0.282, 0.108, 0.1, 0.219, 0.277, 0.343, 0.103, 0.144, 0.042, -0.021, 0.122, 0.242, 0.222, 0.211, 0.107, 0.357, 0.165, 0.329, 0.141, 0.224, 0.354, 0.289, 0.488, 0.083, 0.232, 0.36, 0.198, 0.413, 0.284, 0.37, 0.132, 0.385, 0.479, 0.302, 0.494, 0.289, 0.51, 0.464, 0.732, 0.426, 0.309, 0.473, 0.383, 0.479, 0.611, 0.414, 0.452, 0.643, 0.833, 0.735, 0.433, 0.64, 0.671, 0.417, 0.495, 0.597, 0.514, 0.749, 0.506, 0.486, 0.65, 0.481, 0.533, 0.517, 0.588, 0.821, 0.942, 0.743, 0.859, 0.821, 0.975, 0.625, 0.887, 0.668, 0.794, 0.732, 0.704, 0.706, 0.656, 1.047, 0.784, 0.805, 0.879, 1.133, 0.921, 0.854, 0.698, 1.002, 1.097, 0.957, 0.852, 1.023] performance.add("Overall", dates, overall, mark_point=["max", "min"], mark_line=["average"], is_datazoom_show=True, datazoom_type='both', datazoom_range=[0, 100]) performance.add("Self", dates, self_record, mark_point=["max", "min"], mark_line=["average"], is_datazoom_show=True, datazoom_type='both', datazoom_range=[0, 100], legend_pos="40%") performance.add("Mirror", dates, mirror_record, mark_point=["max", "min"], mark_line=["average"], is_datazoom_show=True, datazoom_type='both', datazoom_range=[0, 100], legend_pos="40%") page.add(performance) portfolio = Pie("Portfolio Summary", **style.init_style) sectors = ['Technology', 'Energy', 'Consumer Cyclical', 'Non-Consumer Cyclical', 'Unclassified'] self_placement = [10000, 20000, 20000, 5000, 2000] mirror_placement = [4000, 2000, 1000, 1000, 2000] over_placement = [self_placement[i] + mirror_placement[i] for i in range(len(self_placement))] portfolio.add("Self", sectors, self_placement, radius=[10, 30], center=[75, 50], is_random=True, rosetype='radius', legend_pos="25%") portfolio.add("Mirror", sectors, mirror_placement, radius=[40, 60], center=[75, 50], is_random=True, rosetype='radius') portfolio.add("Overall", sectors, over_placement, radius=[10, 60], center=[25, 50], is_random=True, rosetype='radius', is_label_show=True) page.add(portfolio) return page
def home(): """ 主页信息 """ # 将要显示的数据 print('test') city_num_list = CITY_NUM_LIST[:100] kw_num_city_list = KW_NUM_OF_ALL_CITY_LIST[:100] lan_num_list = LAN_NUM_LIST job_num_list = JOB_NUM_LIST all_num = ALL_NUM # 生成相应的图表 top_10_city_page = Page() top_10_city_page.add( bar_ssdd( attr_v1_v2=kw_num_city_list[:10], chart_name='前十城市中语言数与职位数对比-折线图', v1_name='语言数量', v2_name='职位数量', )) top_10_city_map_page = Page() top_10_city_map_page.add( geo_qgtd(attr_v1=city_num_list[:10], chart_name='前十城市地理位置', v1_name='城市')) top_100_city_page = Page() top_100_city_page.add( bar_sssf(attr_v1=city_num_list, chart_name='前百城市职位数量-柱状图', v1_name='职位数')) top_100_city_map_page = Page() top_100_city_map_page.add( geo_qgtd(attr_v1=city_num_list[:100], chart_name='前百城市地理位置', v1_name='城市')) lan_page = Page() lan_page.add( pie_yht(attr_v1=lan_num_list, chart_name='各种语言占总数比值-饼图', v1_name='语言')) job_page = Page() job_page.add( pie_yht(attr_v1=job_num_list, chart_name='各种职位占总数比值-饼图', v1_name='职位')) return render_template( 'index.html', title='首页', all_num=all_num, top5_city=DATA.top5_city_name(), top5_lan=DATA.top5_lan_name(), top5_job=DATA.top5_job_name(), top_10_city=top_10_city_page.render_embed(), top_10_city_map_page=top_10_city_map_page.render_embed(), top_100_city_page=top_100_city_page.render_embed(), top_100_city_map_page=top_100_city_map_page.render_embed(), lan_page=lan_page.render_embed(), job_page=job_page.render_embed(), script_list=top_10_city_page.get_js_dependencies() + top_100_city_page.get_js_dependencies() + lan_page.get_js_dependencies() + job_page.get_js_dependencies() + top_10_city_map_page.get_js_dependencies() + top_100_city_map_page.get_js_dependencies(), )
print(data['score'].mean()) score_total = data['score'].value_counts().sort_index() #sort_index(ascending=True) 方法可以对索引进行排序操作 print(score_total) bar = Bar("《流浪地球》各评分数量", width=700) line = Line("", width=700) bar.add("", score_total.index, score_total.values, is_stack=True, is_label_show=True, bar_category_gap='40%', label_color = ['#196845'], legend_text_size=18,xaxis_label_textsize=18,yaxis_label_textsize=18) line.add("", score_total.index, score_total.values+1000, is_smooth=True) overlap = Overlap(width=700) overlap.add(bar) overlap.add(line) #overlap.render() page.add(overlap) # 低分百分比 low_score=score_total[:4].sum()/score_total.sum()*100 # 高分百分比 high_score=score_total[8:].sum()/score_total.sum()*100 # 满分百分比 full_score=score_total[10:].sum()/score_total.sum()*100 print(u'低分占百分比为:{:.3f}%'.format(low_score)) print(u'高分占百分比为:{:.3f}%'.format(high_score)) print(u'满分占百分比为:{:.3f}%'.format(full_score)) ''' 低分占百分比为:3.419% 高分占百分比为:90.625% 满分占百分比为:70.530%
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 = array['close'].tolist() 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 create_charts(): page = Page() style = Style(width=WIDTH, height=HEIGHT) schema = ["data", "AQI", "PM2.5", "PM10", "CO", "NO2"] data = [[1, 91, 45, 125, 0.82, 34], [ 2, 65, 27, 78, 0.86, 45, ], [3, 83, 60, 84, 1.09, 73], [4, 109, 81, 121, 1.28, 68], [5, 106, 77, 114, 1.07, 55], [6, 109, 81, 121, 1.28, 68], [7, 106, 77, 114, 1.07, 55], [8, 89, 65, 78, 0.86, 51, 26], [9, 53, 33, 47, 0.64, 50, 17], [10, 80, 55, 80, 1.01, 75, 24], [11, 117, 81, 124, 1.03, 45]] chart = Parallel("平行坐标系-默认指示器", **style.init_style) chart.config(schema) chart.add("parallel", data, is_random=True) page.add(chart) c_schema = [{ "dim": 0, "name": "data" }, { "dim": 1, "name": "AQI" }, { "dim": 2, "name": "PM2.5" }, { "dim": 3, "name": "PM10" }, { "dim": 4, "name": "CO" }, { "dim": 5, "name": "NO2" }, { "dim": 6, "name": "CO2" }, { "dim": 7, "name": "等级", "type": "category", "data": ['优', '良', '轻度污染', '中度污染', '重度污染', '严重污染'] }] data = [[1, 91, 45, 125, 0.82, 34, 23, "良"], [2, 65, 27, 78, 0.86, 45, 29, "良"], [3, 83, 60, 84, 1.09, 73, 27, "良"], [4, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [5, 106, 77, 114, 1.07, 55, 51, "轻度污染"], [6, 109, 81, 121, 1.28, 68, 51, "轻度污染"], [7, 106, 77, 114, 1.07, 55, 51, "轻度污染"], [8, 89, 65, 78, 0.86, 51, 26, "良"], [9, 53, 33, 47, 0.64, 50, 17, "良"], [10, 80, 55, 80, 1.01, 75, 24, "良"], [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"], [12, 99, 71, 142, 1.1, 62, 42, "良"], [13, 95, 69, 130, 1.28, 74, 50, "良"], [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"]] chart = Parallel("平行坐标系-用户自定义指示器", **style.init_style) chart.config(c_schema=c_schema) chart.add("parallel", data) page.add(chart) return page
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, 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) page.render()
def pyecharts(request): """dashboard view""" # 工单数量统计 chart_dao = ChartDao() bar1 = Bar('SQL上线工单统计(数量)', width="100%") data = chart_dao.workflow_by_date(30) today = date.today() one_month_before = today - relativedelta(days=+30) attr = chart_dao.get_date_list(one_month_before, today) _dict = {} for row in data['rows']: _dict[row[0]] = row[1] value = [_dict.get(day) if _dict.get(day) else 0 for day in attr] bar1.add("月统计", attr, value, is_stack=False, legend_selectedmode='single') # 工单按组统计 pie1 = Pie('SQL上线工单统计(组)', width="100%") data = chart_dao.workflow_by_group(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie1.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 工单按人统计 bar2 = Bar('SQL上线工单统计(用户)', width="100%") data = chart_dao.workflow_by_user(30) attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] bar2.add("月统计", attr, value, is_label_show=True) # SQL语句类型统计 pie2 = Pie("SQL上线工单统计(类型)", width="100%") data = chart_dao.syntax_type() attr = [row[0] for row in data['rows']] value = [row[1] for row in data['rows']] pie2.add("", attr, value, is_label_show=True) # SQL查询统计(每日检索行数) line1 = Line("SQL查询统计", width="100%") attr = chart_dao.get_date_list(one_month_before, today) effect_data = chart_dao.querylog_effect_row_by_date(30) effect_dict = {} for row in effect_data['rows']: effect_dict[row[0]] = int(row[1]) effect_value = [ effect_dict.get(day) if effect_dict.get(day) else 0 for day in attr ] count_data = chart_dao.querylog_count_by_date(30) count_dict = {} for row in count_data['rows']: count_dict[row[0]] = int(row[1]) count_value = [ count_dict.get(day) if count_dict.get(day) else 0 for day in attr ] line1.add("检索行数", attr, effect_value, is_stack=False, legend_selectedmode='single', mark_point=["average"]) line1.add("检索次数", attr, count_value, is_stack=False, legend_selectedmode='single', is_smooth=True, mark_line=["max", "average"]) # SQL查询统计(用户检索行数) pie4 = Pie("SQL查询统计(用户检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_user(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie4.add("月统计", attr, value, radius=[40, 75], is_legend_show=False, is_label_show=True) # SQL查询统计(DB检索行数) pie5 = Pie("SQL查询统计(DB检索行数)", width="100%") data = chart_dao.querylog_effect_row_by_db(30) attr = [row[0] for row in data['rows']] value = [int(row[1]) for row in data['rows']] pie5.add("月统计", attr, value, is_legend_show=False, is_label_show=True) # 可视化展示页面 page = Page() page.add(bar1) page.add(pie1) page.add(bar2) page.add(pie2) page.add(line1) page.add(pie4) page.add(pie5) myechart = page.render_embed() # 渲染配置 host = 'https://pyecharts.github.io/assets/js' # js文件源地址 script_list = page.get_js_dependencies() # 获取依赖的js文件名称(只获取当前视图需要的js) return render(request, "dashboard.html", { "myechart": myechart, "host": host, "script_list": script_list })
def create_charts(): page = Page() style = Style( width=WIDTH, height=HEIGHT ) schema = [ ("销售", 6500), ("管理", 16000), ("信息技术", 30000), ("客服", 38000), ("研发", 52000), ("市场", 25000) ] v1 = [[4300, 10000, 28000, 35000, 50000, 19000]] v2 = [[5000, 14000, 28000, 31000, 42000, 21000]] chart = Radar("雷达图-默认指示器", **style.init_style) chart.config(schema) chart.add("预算分配", v1, is_splitline=True, is_axisline_show=True) chart.add("实际开销", v2, label_color=["#4e79a7"], is_area_show=False, legend_selectedmode='single') page.add(chart) value_bj = [ [55, 9, 56, 0.46, 18, 6, 1], [25, 11, 21, 0.65, 34, 9, 2], [56, 7, 63, 0.3, 14, 5, 3], [33, 7, 29, 0.33, 16, 6, 4], [42, 24, 44, 0.76, 40, 16, 5], [82, 58, 90, 1.77, 68, 33, 6], [74, 49, 77, 1.46, 48, 27, 7], [78, 55, 80, 1.29, 59, 29, 8], [267, 216, 280, 4.8, 108, 64, 9], [185, 127, 216, 2.52, 61, 27, 10], [39, 19, 38, 0.57, 31, 15, 11], [41, 11, 40, 0.43, 21, 7, 12], [64, 38, 74, 1.04, 46, 22, 13], [108, 79, 120, 1.7, 75, 41, 14], [108, 63, 116, 1.48, 44, 26, 15], [33, 6, 29, 0.34, 13, 5, 16], [94, 66, 110, 1.54, 62, 31, 17], [186, 142, 192, 3.88, 93, 79, 18], [57, 31, 54, 0.96, 32, 14, 19], [22, 8, 17, 0.48, 23, 10, 20], [39, 15, 36, 0.61, 29, 13, 21], [94, 69, 114, 2.08, 73, 39, 22], [99, 73, 110, 2.43, 76, 48, 23], [31, 12, 30, 0.5, 32, 16, 24], [42, 27, 43, 1, 53, 22, 25], [154, 117, 157, 3.05, 92, 58, 26], [234, 185, 230, 4.09, 123, 69, 27], [160, 120, 186, 2.77, 91, 50, 28], [134, 96, 165, 2.76, 83, 41, 29], [52, 24, 60, 1.03, 50, 21, 30], [46, 5, 49, 0.28, 10, 6, 31] ] value_sh = [ [91, 45, 125, 0.82, 34, 23, 1], [65, 27, 78, 0.86, 45, 29, 2], [83, 60, 84, 1.09, 73, 27, 3], [109, 81, 121, 1.28, 68, 51, 4], [106, 77, 114, 1.07, 55, 51, 5], [109, 81, 121, 1.28, 68, 51, 6], [106, 77, 114, 1.07, 55, 51, 7], [89, 65, 78, 0.86, 51, 26, 8], [53, 33, 47, 0.64, 50, 17, 9], [80, 55, 80, 1.01, 75, 24, 10], [117, 81, 124, 1.03, 45, 24, 11], [99, 71, 142, 1.1, 62, 42, 12], [95, 69, 130, 1.28, 74, 50, 13], [116, 87, 131, 1.47, 84, 40, 14], [108, 80, 121, 1.3, 85, 37, 15], [134, 83, 167, 1.16, 57, 43, 16], [79, 43, 107, 1.05, 59, 37, 17], [71, 46, 89, 0.86, 64, 25, 18], [97, 71, 113, 1.17, 88, 31, 19], [84, 57, 91, 0.85, 55, 31, 20], [87, 63, 101, 0.9, 56, 41, 21], [104, 77, 119, 1.09, 73, 48, 22], [87, 62, 100, 1, 72, 28, 23], [168, 128, 172, 1.49, 97, 56, 24], [65, 45, 51, 0.74, 39, 17, 25], [39, 24, 38, 0.61, 47, 17, 26], [39, 24, 39, 0.59, 50, 19, 27], [93, 68, 96, 1.05, 79, 29, 28], [188, 143, 197, 1.66, 99, 51, 29], [174, 131, 174, 1.55, 108, 50, 30], [187, 143, 201, 1.39, 89, 53, 31] ] c_schema = [ {"name": "AQI", "max": 300, "min": 5}, {"name": "PM2.5", "max": 250, "min": 20}, {"name": "PM10", "max": 300, "min": 5}, {"name": "CO", "max": 5}, {"name": "NO2", "max": 200}, {"name": "SO2", "max": 100} ] chart = Radar("雷达图-用户自定义指示器", **style.init_style) chart.config(c_schema=c_schema, shape='circle') chart.add("北京", value_bj, item_color="#f9713c", symbol=None) chart.add("上海", value_sh, item_color="#b3e4a1", symbol=None, legend_selectedmode='single') page.add(chart) chart = Radar("雷达图-用户自定义指示器", **style.init_style) chart.config(c_schema=c_schema, shape='circle') chart.add("北京", value_bj, item_color="#f9713c", symbol=None) chart.add("上海", value_sh, item_color="#b3e4a1", symbol=None) page.add(chart) return page
from pyecharts import Page, Style x = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] y1 = [5, 20, 36, 10, 75, 90] y2 = [10, 25, 8, 60, 20, 80] page = Page() style = Style() bar_style = style.add(mark_point=["max", "min"], mark_line=["average"], is_label_show=True, is_more_utils=True) bar = Bar() bar.add('', x, y1, **bar_style) bar.add('', x, y2, **bar_style) page.add(bar) line = Line() line_style = style.add(mark_point=["max", "min"], mark_line=["average"], is_label_show=False, is_more_utils=False, is_stack=True, is_fill=True, area_opacity=0.5) line.add('', x, y1, **line_style) line.add('', x, y2, **line_style) page.add(line) pie = Pie("饼图-玫瑰图示例") pie_style = style.add(is_random=True,
def analyst(): """颜色,型号,内存""" color_c = Counter() model_c = Counter() ram_c = Counter() db = init_mongodb() cur = db['comments'] for g in cur.find({}, {'color': 1, 'model': 1, 'ram': 1, '_id': 0}): # 颜色清洗 color = g['color'] if ' ' in color: color = color.split()[0] color_c[color] += 1 # ram 清洗 ram = g['ram'] if ram: ram_c[ram] += 1 # model 清洗 model = g['model'] excludes = ['手机', '白条免息', '电信老人机'] if model not in excludes: model_c[model] += 1 # for (k, v) in c.most_common(100): # print(k, v) # 饼图 page = Page() style = Style(width=800, height=800) ## color attr = color_c.keys() v1 = color_c.values() chart = Pie("颜色", **style.init_style) chart.add("", attr, v1, is_label_show=True) page.add(chart) ## model attr = model_c.keys() v1 = model_c.values() chart = Pie("型号", title_pos='center', **style.init_style) chart.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='left') page.add(chart) ## ram attr = ram_c.keys() v1 = ram_c.values() chart = Pie("内存", title_pos='center', **style.init_style) chart.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical', legend_pos='right') page.add(chart) page.render(path="result.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 PL_draw_echarts(PL_df, PL_slices): # 初始化一个画图的页面.每一种信号画一张图片 PL_page = Page() PL_columns = PL_df.columns.values.tolist() # 所有统计的信号种类 PL_signal_items = list(set(PL_df['signal_name'].tolist())) PL_signal_items.sort() # 所有的N[第n个bar] PL_bar_nos = [] for PL_col in PL_columns: if re.match('chg_pct_', PL_col): # 获取当前统计的是第几根bar的收益 PL_bar_nos.append(PL_col.replace('chg_pct_', '')) for PL_sig in PL_signal_items: # 获取一种信号在M个bar内的收益统计 PL_bar = Bar(PL_sig + "收益分布", title_text_size=14, width='100%') PL_sdf = PL_df[(PL_df['signal_name'] == PL_sig)] if PL_sdf.empty: continue # 划分收益区间,从0开始往正负两端划分收益区间 # 计算每个收益区间的大小 PL_max_profit = 0 PL_min_profit = 0 for PL_no in PL_bar_nos: PL_pcol = 'chg_pct_' + PL_no PL_profits = PL_sdf[PL_pcol].tolist() PL_max_profit = max(max(PL_profits), PL_max_profit) PL_min_profit = min(min(PL_profits), PL_min_profit) PL_intervals = [] if PL_min_profit < 0: PL_unit = round( max(PL_max_profit, abs(PL_min_profit)) / PL_slices, 4) # 先划分小于0的区间 for i in range(0, int(math.ceil(abs(PL_min_profit) / PL_unit))): PL_intervals.append( [round(-(i + 1) * PL_unit, 4), round(-i * PL_unit, 4)]) PL_intervals.reverse() else: PL_unit = PL_max_profit / PL_slices for i in range(0, int(math.ceil(abs(PL_max_profit) / PL_unit))): PL_intervals.append([i * PL_unit, (i + 1) * PL_unit]) # 显示收益区间之前先格式化成百分比。 PL_format_intervals = [ '%.2f%%~%.2f%%' % (i[0] * 100, i[1] * 100) for i in PL_intervals ] for PL_no in PL_bar_nos: # 计算第M个bar收益,落在某一个收益区间的概率 PL_win_ratios = [] PL_pcol = 'chg_pct_' + PL_no for PL_interval in PL_intervals: # 统计在收益落在某个收益区间的概率 PL_conf = (PL_sdf[PL_pcol] > PL_interval[0]) & ( PL_sdf[PL_pcol] <= PL_interval[1]) # 避免int类型直接除之后返回的还是int,这里*1.0 PL_win_ratios.append( round(len(PL_sdf[PL_conf]) / (len(PL_sdf) * 1.0), 2)) PL_bar.add( "第%s个bar" % PL_no, PL_format_intervals, PL_win_ratios, xaxis_name='收益区间', xaxis_name_pos='end', xaxis_name_size=12, xaxis_label_textsize=12, xaxis_interval=1, xaxis_rotate=45, yaxis_name='概率', yaxis_name_pos='end', yaxis_name_size=12, yaxis_label_textsize=12, is_splitline_show=False, # 默认为 X 轴,横向 is_datazoom_show=True, datazoom_type="both", datazoom_range=[40, 60], # 额外的 dataZoom 控制条,纵向 # is_datazoom_extra_show=True, # datazoom_extra_type="slider", # datazoom_extra_range=[10, 25], # is_toolbox_show=False, ) PL_grid = Grid(width='100%') PL_grid.add(PL_bar, grid_bottom=120) PL_page.add(PL_grid) PL_page.render()
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()
Title = 数据可视化 """ from pyecharts import Bar, Scatter3D, Line, Overlap from pyecharts import Page import random page = Page() # 竖行条形图 bar = Bar('阳阳日常分析表','女神阳阳分析表') bar.use_theme('dark') # 添加条数据 bar.add('时间',['睡觉','吃饭','化妆','做饭','发呆','看电视'],[10,0.5,1,1,3,4]) # 添加条数据 bar.add('钱',['睡觉','吃饭','化妆','做饭','发呆','看电视'],[0,1,30,1,0,0.5]) page.add(bar) # 带折线的竖行条形图 bar = Bar('阳阳日常分析表2','女神阳阳分析表') bar.use_theme('dark') data1 = [10,0.5,1,1,3,4] data2 = [0,1,30,1,0,0.5] data_line1 = [11,1.5,2,3,4,6] data_line2 = [1,1.5,31,3,4,6] # 添加条数据 bar.add('时间',['睡觉','吃饭','化妆','做饭','发呆','看电视'],data1) # 添加条数据 bar.add('钱',['睡觉','吃饭','化妆','做饭','发呆','看电视'],data2) line = Line()
def create_charts(): page = Page() data = [['2015/11/08', 10, 'DQ'], ['2015/11/09', 15, 'DQ'], ['2015/11/10', 35, 'DQ'], ['2015/11/14', 7, 'DQ'], ['2015/11/15', 2, 'DQ'], ['2015/11/16', 17, 'DQ'], ['2015/11/17', 33, 'DQ'], ['2015/11/18', 40, 'DQ'], ['2015/11/19', 32, 'DQ'], ['2015/11/20', 26, 'DQ'], ['2015/11/21', 35, 'DQ'], ['2015/11/22', 40, 'DQ'], ['2015/11/23', 32, 'DQ'], ['2015/11/24', 26, 'DQ'], ['2015/11/25', 22, 'DQ'], ['2015/11/08', 35, 'TY'], ['2015/11/09', 36, 'TY'], ['2015/11/10', 37, 'TY'], ['2015/11/11', 22, 'TY'], ['2015/11/12', 24, 'TY'], ['2015/11/13', 26, 'TY'], ['2015/11/14', 34, 'TY'], ['2015/11/15', 21, 'TY'], ['2015/11/16', 18, 'TY'], ['2015/11/17', 45, 'TY'], ['2015/11/18', 32, 'TY'], ['2015/11/19', 35, 'TY'], ['2015/11/20', 30, 'TY'], ['2015/11/21', 28, 'TY'], ['2015/11/22', 27, 'TY'], ['2015/11/23', 26, 'TY'], ['2015/11/24', 15, 'TY'], ['2015/11/25', 30, 'TY'], ['2015/11/26', 35, 'TY'], ['2015/11/27', 42, 'TY'], ['2015/11/28', 42, 'TY'], ['2015/11/08', 21, 'SS'], ['2015/11/09', 25, 'SS'], ['2015/11/10', 27, 'SS'], ['2015/11/11', 23, 'SS'], ['2015/11/12', 24, 'SS'], ['2015/11/13', 21, 'SS'], ['2015/11/14', 35, 'SS'], ['2015/11/15', 39, 'SS'], ['2015/11/16', 40, 'SS'], ['2015/11/17', 36, 'SS'], ['2015/11/18', 33, 'SS'], ['2015/11/19', 43, 'SS'], ['2015/11/20', 40, 'SS'], ['2015/11/21', 34, 'SS'], ['2015/11/22', 28, 'SS'], ['2015/11/14', 7, 'QG'], ['2015/11/15', 2, 'QG'], ['2015/11/16', 17, 'QG'], ['2015/11/17', 33, 'QG'], ['2015/11/18', 40, 'QG'], ['2015/11/19', 32, 'QG'], ['2015/11/20', 26, 'QG'], ['2015/11/21', 35, 'QG'], ['2015/11/22', 40, 'QG'], ['2015/11/23', 32, 'QG'], ['2015/11/24', 26, 'QG'], ['2015/11/25', 22, 'QG'], ['2015/11/26', 16, 'QG'], ['2015/11/27', 22, 'QG'], ['2015/11/28', 10, 'QG'], ['2015/11/08', 10, 'SY'], ['2015/11/09', 15, 'SY'], ['2015/11/10', 35, 'SY'], ['2015/11/11', 38, 'SY'], ['2015/11/12', 22, 'SY'], ['2015/11/13', 16, 'SY'], ['2015/11/14', 7, 'SY'], ['2015/11/15', 2, 'SY'], ['2015/11/16', 17, 'SY'], ['2015/11/17', 33, 'SY'], ['2015/11/18', 40, 'SY'], ['2015/11/19', 32, 'SY'], ['2015/11/20', 26, 'SY'], ['2015/11/21', 35, 'SY'], ['2015/11/22', 4, 'SY'], ['2015/11/23', 32, 'SY'], ['2015/11/24', 26, 'SY'], ['2015/11/25', 22, 'SY'], ['2015/11/26', 16, 'SY'], ['2015/11/27', 22, 'SY'], ['2015/11/28', 10, 'SY'], ['2015/11/08', 10, 'DD'], ['2015/11/09', 15, 'DD'], ['2015/11/10', 35, 'DD'], ['2015/11/11', 38, 'DD'], ['2015/11/12', 22, 'DD'], ['2015/11/13', 16, 'DD'], ['2015/11/14', 7, 'DD'], ['2015/11/15', 2, 'DD'], ['2015/11/16', 17, 'DD'], ['2015/11/17', 33, 'DD'], ['2015/11/18', 4, 'DD'], ['2015/11/19', 32, 'DD'], ['2015/11/20', 26, 'DD'], ['2015/11/21', 35, 'DD'], ['2015/11/22', 40, 'DD'], ['2015/11/23', 32, 'DD'], ['2015/11/24', 26, 'DD'], ['2015/11/25', 22, 'DD']] chart = ThemeRiver("主题河流图") chart.add(['DQ', 'TY', 'SS', 'QG', 'SY', 'DD'], data, is_label_show=True) page.add(chart) return page
class JDPage: def __init__(self, product): self.page = Page() self.product = product self.attr_title_dict = {'product_size': "不同配置购买量", 'product_color': "不同颜色购买量", 'level': "用户等级", 'client': "用户客户端", 'after_days': '购买多少天后评论'} def generate_stacked_bar_charts(self): """ 生成不同配置购买量、不同颜色购买量、用户等级和用户客户端的层叠条形图 """ titles = ['好评', '中评', '差评'] for attr in self.attr_title_dict.keys(): d = {} for c in self.product.get_all_comments(): temp = getattr(c, attr) if c.score > 3: index = 0 elif c.score > 1: index = 1 else: index = 2 if d.get(temp): d[temp][index] += 1 else: d[temp] = [0, 0, 0] d[temp][index] = 1 v = [[], [], []] if attr == 'after_days': # 使得x轴名称能按照从少到多的顺序 a = ['0-10天', '11-20天', '21-30天', '31-60天', '60天后'] for k in a: for i in range(3): v[i].append(d.get(k)[i]) else: a = [] for k in d.keys(): if k == '': a.append('网页') else: a.append(k) for i in range(3): v[i].append(d.get(k)[i]) chart = Bar(self.attr_title_dict.get(attr)) for i in range(3): chart.add(titles[i], a, v[i], xaxis_interval=0, is_stack=True) self.page.add(chart) def generate_pie_charts(self): """ 生成饼图 """ # 生成各种评价占比的饼图 a = ["默认好评", "好评", "中评", "差评"] v = [self.product.default_good_count, self.product.good_count - self.product.default_good_count, self.product.general_count, self.product.poor_count] pie = Pie("好评,中评,差评") pie.add("", a, v, is_label_show=True) self.page.add(pie) comments = self.product.get_all_comments() # 匿名评论情况饼图 v = [0, 0] for c in comments: if c.isAnonymous: v[0] += 1 else: v[1] += 1 chart = Pie('匿名评论情况') chart.add('', ['匿名', '非匿名'], v, xaxis_interval=0) self.page.add(chart) # 生成不同配置购买量、不同颜色购买量、用户等级和用户客户端的饼图 for attr in self.attr_title_dict.keys(): d = {} for c in comments: temp = getattr(c, attr) if d.get(temp): d[temp] += 1 else: d[temp] = 1 a = [] v = [] for k in d.keys(): if k == '': a.append('网页') else: a.append(k) v.append(d.get(k)) if attr == 'level': # 解决图例过长遮挡标题的bug chart = Pie('') else: chart = Pie(self.attr_title_dict.get(attr)) chart.add("", a, v, is_label_show=True) self.page.add(chart) def generate_word_cloud_charts(self): """ 生成词云图 """ # 热评词云 attr = [] val = [] for t in self.product.hot_comment_tags: attr.append(t.get('name')) val.append(int(t.get('count'))) hot_tags_wc = make_word_cloud("热评词云", attr, val) self.page.add(hot_tags_wc) # 好评,中评,差评词云 d = [('好评词云', 'good_comments'), ('中评词云', 'general_comments'), ('差评词云', 'poor_comments')] for i in range(3): a, v = get_summary_and_weight(getattr(self.product, d[i][1])) wc = make_word_cloud(d[i][0], a, v) self.page.add(wc)
def line_charts(): page = Page() chart_init = { "width": WIDTH, "height": HEIGHT, } attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 10, 100] v2 = [55, 60, 16, 20, 15, 80] chart = Line("折线图-默认标记", **chart_init) chart.add("商家A", attr, v1, mark_point=["average"]) chart.add("商家B", attr, v2, is_smooth=True, mark_line=["max", "average"], is_more_utils=True) page.add(chart) chart = Line("折线图-自定义标记", **chart_init) chart.add( "商家A", attr, v1, mark_point=["average", { "coord": ["裤子", 10], "name": "这是我想要的第一个标记点" }]) chart.add("商家B", attr, v2, is_smooth=True, is_more_utils=True, mark_point=[{ "coord": ["袜子", 80], "name": "这是我想要的第二个标记点" }]) page.add(chart) chart = Line("折线图-标记图标", **chart_init) chart.add("商家A", attr, v1, mark_point=["average", "max", "min"], mark_point_symbol='diamond', mark_point_textcolor='#40ff27') chart.add("商家B", attr, v2, mark_point=["average", "max", "min"], mark_point_symbol='arrow', mark_point_symbolsize=40) page.add(chart) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] chart = Line("折线图-某地气温", **chart_init) chart.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) chart.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"]) page.add(chart) attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 10, 100] v2 = [55, 60, 16, 20, 15, 80] chart = Line("折线图-数据堆叠", **chart_init) chart.add("商家A", attr, v1, is_stack=True, is_label_show=True) chart.add("商家B", attr, v2, is_stack=True, is_label_show=True) page.add(chart) chart = Line("折线图-阶梯图", **chart_init) chart.add("商家A", attr, v1, is_step=True, is_label_show=True) page.add(chart) chart = Line("折线图-面积图", **chart_init) chart.add("商家A", attr, v1, is_fill=True, line_opacity=0.2, area_opacity=0.4, symbol=None) chart.add("商家B", attr, v2, is_fill=True, area_color='#000', area_opacity=0.3, is_smooth=True) page.add(chart) chart = Line("折线图-对数坐标轴", width=WIDTH, height=HEIGHT) chart.add("商家A", attr, [math.log10(random.randint(1, 99999)) for _ in range(6)]) chart.add("商家B", attr, [math.log10(random.randint(1, 99999999)) for _ in range(6)], yaxis_type="log") page.add(chart) return page
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()
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()