def backend_development_avg_salary(): print("正在计算后端开发各个城市薪资......") data = sel_backend_development_avg_salary() print(data) x_axis = city_list y_axis = Backend_development_list avg_salary_list = [] for x in range(9): for y in range(12): for i in data: if i["avg_salary"] == None: i["avg_salary"] = '0' avg_salary_list.append([x, y, i["avg_salary"]]) #print(avg_salary_list[::109]) 防止3次循环产生的笛卡尔积 需要隔 x * y 中取数 avg_salary_list = avg_salary_list[::109] heatmap = HeatMap( "各地后端开发薪资水平", background_color='#F4F3EF', ) heatmap.add("", x_axis, y_axis, avg_salary_list, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal', visual_range=[0, 30], visual_range_text=['0', '30k']) return heatmap
def view_date_hot(self): """ 需要的数据 self.start_year str() 用于显示在网页和html文件名上 self.data_dict 展示的数据: [["year-month-day", value],["year-month-day", value],["year-month-day", value]] """ print("开始生成 %s年 %s每日销货汇总热力图" % (self.start_year, self.table_name)) heat_map = HeatMap("%s每日销货汇总热力图" % self.table_name, "%s年" % self.start_year, width=1200, page_title="Calendar") heat_map.add( "", self.data_dict, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=['', ''], visual_range=[0, max(self.data_dict, key=lambda x: x[1])[1]], calendar_cell_size=['auto', 30], is_visualmap=True, calendar_date_range=str(self.start_year), visual_pos="5%", visual_top="75%", visual_orient='horizontal', is_toolbox_show=False) heat_map.render( path=self.BASE_PATH + "{}{}_data_hot.html".format(self.start_year, self.html_name))
def Artificial_intelligence_avg_salary(): print("正在计算人工智能开发各个城市薪资......") data = sel_Artificial_intelligence_avg_salary() print(data) x_axis = city_list y_axis = Artificial_intelligence_list avg_salary_list = [] for x in range(9): for y in range(8): for i in data: if i["avg_salary"] == None: i["avg_salary"] = '0' avg_salary_list.append([x, y, i["avg_salary"]]) #print(avg_salary_list[::73]) #防止3次循环产生的笛卡尔积 需要隔 (x * y)+1中取数 avg_salary_list = avg_salary_list[::73] heatmap = HeatMap( "各地人工智能开发薪资水平", background_color='#F4F3EF', ) heatmap.add("", x_axis, y_axis, avg_salary_list, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal', visual_range=[0, 30], visual_range_text=['0', '30k']) return heatmap
def test_grid_5(): import random x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p" ] y_axis = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday" ] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700) heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal') attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_top="50%") grid = Grid() grid.add(heatmap, grid_bottom="60%") grid.add(bar, grid_top="60%") grid.render()
def Normal(params,chartname="",filename="usage_ana"): ''' params:list,内嵌元组或列表的列表,格式为:[("2019-2-8",32)] chartname:str,图表名 filename:str,文件名,存储在output文件夹下 ''' day_counter = [] for i in params: day_counter.append(i[1]) heatmap = HeatMap(chartname, "", width=1500) heatmap.add( "", params, is_label_show=True, tooltip_formatter='{c}', is_calendar_heatmap=True, visual_text_color="#000", visual_range_text=["", ""], visual_range=[1, int(max(day_counter))], calendar_cell_size=["auto", 30], is_visualmap=True, # calendar_date_range="2015", calendar_date_range=[params[0][0], params[-1][0]], visual_orient="horizontal", visual_pos="center", visual_top="80%", is_piecewise=True, ) heatmap.render(path="../../output/"+filename+".html") heatmap.render(path="../../output/"+filename+".pdf")
def test_heatmap_calendar(): import datetime begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 12, 31) data = [[ str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000) ] for i in range((end - begin).days + 1)] heatmap = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=1100) heatmap.add( "", data, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=['', ''], visual_range=[1000, 25000], calendar_cell_size=['auto', 30], is_visualmap=True, calendar_date_range="2017", visual_orient="horizontal", visual_pos="center", visual_top="80%", is_piecewise=True, ) heatmap.render()
def heatmap(self, year): das = {} for item in self.data: d = datetime.fromtimestamp(item[2]) if (d.year == year): das[date(d.year, d.month, d.day)] = das.get( date(d.year, d.month, d.day), 0) + item[1] result = [[str(key), das[key]] for key in das] y_min = min([das[key] for key in das]) y_max = max([das[key] for key in das]) heatmap = HeatMap('说说点赞之日历热力图', title_pos='center', width=1100) heatmap.add("", result, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=["", ""], visual_range=[y_min, y_max], calendar_cell_size=["auto", 30], is_visualmap=True, calendar_date_range=str(year), visual_orient="horizontal", visual_pos='center', visual_top='80%', is_piecewise=True) heatmap.render(self.path + 'heatmap' + str(year) + '_' + str(int(time.time())) + '.html') webbrowser.open_new_tab(self.path + 'heatmap' + str(year) + '_' + str(int(time.time())) + '.html') self.ins.analysis_pb['value'] = 100 self.ins.analysis_lb.configure(text='完毕')
def test_heatmap_calendar(): import datetime begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 12, 31) data = [ [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)] for i in range((end - begin).days + 1) ] heatmap = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=1100) heatmap.add( "", data, is_calendar_heatmap=True, visual_text_color="#000", visual_range_text=["", ""], visual_range=[1000, 25000], calendar_cell_size=["auto", 30], is_visualmap=True, calendar_date_range="2017", visual_orient="horizontal", visual_pos="center", visual_top="80%", is_piecewise=True, ) heatmap.render()
def heatmap_2attr(df, attr1, attr2, func=len, value=None, order_type=[0, 0]): if value == None: df2 = df.groupby([attr1, attr2])[attr1].agg([func]) else: df2 = df.groupby([attr1, attr2])[value].agg([func]) df2 = df2.reset_index() x_axis = ordered_attr(df2, attr1, attr2, order_type[0]) y_axis = ordered_attr(df2, attr2, attr1, order_type[1]) data = [[x_axis.index(i), y_axis.index(j), df2.loc[(df2[attr1] == i) & (df2[attr2] == j), func.__name__]] for i in x_axis for j in y_axis] heatmap = HeatMap() heatmap.add("热力图直角坐标系", x_axis, y_axis, data, xaxis_name=attr1, yaxis_name=attr2, xaxis_interval=0, xaxis_label_textsize=10, xaxis_name_gap=30, yaxis_label_textsize=10, yaxis_name_gap=30, yaxis_rotate=90, is_visualmap=True, visual_range=[min(df2[func.__name__]), max(df2[func.__name__])], visual_text_color="#000", visual_orient='horizontal') return heatmap
def test_heatmap_default(): data = [ [i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal', xaxis_name='XNAME', yaxis_name='YNAME', yaxis_name_pos='end', yaxis_name_gap=5) heatmap.render()
def test_heatmap_default(): data = [ [i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal', xaxis_name='XNAME', yaxis_name='YNAME', yaxis_name_pos='end', yaxis_name_gap=5) heatmap.render()
def test_heatmap(): import random data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') heatmap.render()
def test_heatmap(): # heatmap_0 import random x_axis = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"] y_aixs = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add("热力图直角坐标系", x_axis, y_aixs, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') heatmap.show_config() heatmap.render()
def generate_heatmap(): data = pd.read_excel(input_file_path + '每日销量.xlsx', sheet_name=0) print(data.head()) x_axis = data['week'].tolist() data['week'] = data['week'].str.replace('week', '').map(int) - 1 data = data.set_index('week') y_axis = data.columns.tolist() data.columns = range(0, 7) data = data.stack().reset_index() data.columns = ['week', 'day', 'amount'] heatmap = HeatMap() heatmap.add('全年产量情况', x_axis, y_axis, data.values.tolist(), is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') heatmap.render(output_file_path + 'htmls/全年产量情况热力图.html')
def heatmap_charts(): page = Page() data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] chart = HeatMap("热力图示例", width=WIDTH, height=HEIGHT) chart.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') page.add(chart) return page
def test_grid_heatmap_bar(): data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700) heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal') attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_top="50%") grid = Grid() grid.add(heatmap, grid_bottom="60%") grid.add(bar, grid_top="60%") grid.render()
def test_grid_heatmap_bar(): data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700) heatmap.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal') v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", CLOTHES, v1, is_stack=True) bar.add("商家B", CLOTHES, v2, is_stack=True, legend_top="50%") grid = Grid() grid.add(heatmap, grid_bottom="60%") grid.add(bar, grid_top="60%") grid.render()
def test_heatmap_display_yaxis_label(): data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap() heatmap.add( "热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, is_label_show=False, visual_text_color="#000", visual_orient="horizontal", ) html_content = heatmap._repr_html_() assert r'"formatter": "{value} "' not in html_content assert "Saturday" in html_content assert "Monday" in html_content
def corr_heatmap(data,report=False,file_name='Pairwise_Heatmap.html'): # draing correlation heatmap for data Temp_pairwise_df = data.corr() Temp_pairwise_df = Temp_pairwise_df.fillna(0) Temp_pairwise_df = Temp_pairwise_df*100 Temp_pairwise_df = np.round(Temp_pairwise_df,2) x_axis = list(Temp_pairwise_df.index) y_axis = list(Temp_pairwise_df.columns) data = [[x_axis[i],y_axis[j],Temp_pairwise_df[x_axis[i]][y_axis[j]]] for i in range(len(x_axis)) for j in range(len(y_axis))] heatmap = HeatMap() heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True,visual_range=[0,100], visual_text_color="#000", visual_orient='horizontal',is_label_emphasis=True,label_emphasis_pos='inside', label_emphasis_textcolor="#000",label_emphasis_textsize=15,tooltip_tragger='item',tooltip_formatter='{c}', is_datazoom_show=True,datazoom_type='both',visual_top=0.1,is_more_utils=True) if report == False: return heatmap else: return heatmap.render(file_name)
def test_heatmap_default(): data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add( "热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient="horizontal", xaxis_name="XNAME", yaxis_name="YNAME", yaxis_name_pos="end", yaxis_name_gap=5, ) html_content = heatmap._repr_html_() assert "Saturday" in html_content assert "Monday" in html_content
def heatmap_2attr(df, attr1, attr2, func=len, value=None): if value==None: df2=df.groupby([attr1, attr2])[attr1].agg([func]) else: df2=df.groupby([attr1, attr2])[value].agg([func]) df2=df2.reset_index() x_axis = list(set(df2[attr1])) y_axis = list(set(df2[attr2])) data = [[x_axis.index(i), y_axis.index(j), df2.loc[(df2[attr1]==i) & (df2[attr2]==j), func.__name__]] for i in x_axis for j in y_axis] print(data) heatmap = HeatMap() heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True, visual_range=[0, max(df2[func.__name__])], visual_text_color="#000", visual_orient='horizontal') heatmap.render()
def page(player_id: int = None): # init_list = json_load('matches') if not player_id: init_list = get_player_matches_json(129689355) else: init_list = get_player_matches_json(player_id) # print(len(init_list)) init_dict = {} data = [] for row in init_list: start_time = datetime.fromtimestamp( row['start_time']).strftime("%Y-%m-%d") if start_time not in init_dict: init_dict[start_time] = 1 else: init_dict[start_time] += 1 for key in init_dict: val = init_dict[key] key = datetime.strptime(key, "%Y-%m-%d") tmp = [] tmp.extend((key, val)) data.append(tmp) page = Page() year = int(datetime.today().strftime("%Y")) for i in range(year, 2016, -1): heatmap = HeatMap(height=250, width=1100) heatmap.add("", data, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=['', ''], visual_range=[0, 15], calendar_cell_size=['auto', 20], is_visualmap=True, calendar_date_range=str(i), visual_orient="horizontal", visual_pos="center", visual_top="90%", is_piecewise=True) page.add(heatmap) return page
def reli(t): x_axis, y_axis, y = [], [], [] for i in t: x_axis.append(i[0]) Str = ''.join(i[1].split(',')) # 注意这里i[2]是一个对象 y.append(int(int(Str) / 200)) # print(x_axis, y) y_axis = ["one", "two", "three", "four", "five", "six"] da, data = [], [] for i in y: # 生成7个随机数,是他们的和为i while 1: n1 = random.randint(0, i) n2 = random.randint(0, i) n3 = random.randint(0, i) n4 = random.randint(0, i) n5 = random.randint(0, i) n6 = random.randint(0, i) su = n1 + n2 + n3 + n4 + n5 + n6 if su == i: listRandom = n1, n2, n3, n4, n5, n6 break da.append(listRandom) for i in range(50): for j in range(6): x = [i, j, da[i][j]] data.append(x) # print(data) heatmap = HeatMap() heatmap.add( "电影热力图", x_axis, y_axis, data, is_visualmap=True, visual_text_color="#000", visual_orient="horizontal", ) heatmap.render(pathConfig.HTLMSREPATH + '电影热力图.html')
def create_charts(): page = Page() data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] chart = HeatMap("热力图示例", width=WIDTH, height=HEIGHT) chart.add("热力图直角坐标系", X_TIME, Y_WEEK, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') page.add(chart) import datetime begin = datetime.date(2017, 1, 1) end = datetime.date(2017, 12, 31) data = [[ str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000) ] for i in range((end - begin).days + 1)] chart = HeatMap("日历热力图示例", "某人 2017 年微信步数情况", width=WIDTH) chart.add("", data, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=['', ''], visual_range=[1000, 25000], calendar_cell_size=['auto', 30], is_visualmap=True, calendar_date_range="2017", visual_orient="horizontal", visual_pos="center", visual_top="80%", is_piecewise=True) page.add(chart) return page
def v_correlation(self, end=yesterdayobj(), **vkwds): ''' 各基金净值的相关程度热力图可视化 :param end: string or object of date, the end date of the line :returns: pyecharts.Heatmap object ''' ctable = self.correlation_table(end) x_axis = list(ctable.columns) data = [[i, j, ctable.iloc[i, j]] for i in range(len(ctable)) for j in range(len(ctable))] heatmap = HeatMap() heatmap.add("", x_axis, x_axis, data, is_visualmap=True, visual_pos='center', visual_text_color="#000", visual_range=[-1, 1], visual_orient='horizontal', **vkwds) return heatmap
def test_heatmap(): # heatmap_0 import random x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p" ] y_axis = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday" ] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例") heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') heatmap.render()
def plot_interactive_monthly_heatmap(returns: pd.Series) -> Chart: """ Plots a heatmap of returns by month. """ monthly_ret_table = ep.aggregate_returns(returns, 'monthly') monthly_ret_table = monthly_ret_table.unstack().round(3) monthly_ret_table = np.round(monthly_ret_table * 100, 2) lim = lim = max(np.max(np.abs(monthly_ret_table))) y_axis = [date(1000, i, 1).strftime('%b') for i in range(1, 13)] x_axis = [str(y) for y in monthly_ret_table.index.tolist()] data = data = [[x_axis[i], y_axis[j], monthly_ret_table.values[i][j]] for i in range(monthly_ret_table.shape[0]) for j in range(monthly_ret_table.shape[1])] heatmap = HeatMap("Monthly Returns") heatmap.add( "Monthly Returns", x_axis, y_axis, data, is_visualmap=True, is_datazoom_show=True, datazoom_orient='horizontal', datazoom_range=[0, 100], visual_range=[-lim, lim], visual_text_color="#000", visual_range_color=['#D73027', '#FFFFBF', '#1A9641'], visual_orient="vertical", is_toolbox_show=False, is_label_show=True, label_pos="inside", label_text_color="black", tooltip_formatter="{c}%" ) return heatmap
def picture_heatmap(file_path_hcs): df_hcs = pd.read_csv(file_path_hcs, encoding='utf-8', usecols=['Date', 'AQI']) data_hcs = [] for index_hcs, col_hcs in df_hcs.iterrows(): data_hcs.append([col_hcs[0], col_hcs[1]]) hm_hcs = HeatMap('广州市2018年的空气质量指数日历热力图——黄彩思') # 参照https://www.jianshu.com/p/fc8c78e0df98 hm_hcs.add( '', data_hcs, is_calendar_heatmap=True, is_visualmap=True, calendar_date_range='2018', calendar_cell_size=['auto', 30], is_toolbox_show=False, visual_range=[10, 200], visual_split_number=5, is_piecewise=True, visual_orient="horizontal", visual_pos="center", ) hm_hcs.render('hearmap_AQI.html')
def heatmap_is_calendar(title, year, datas, size=None): """ 输出日历热力图 :param title: 标题 :param year: 年份,如"2018" :param datas: 数据,格式:[[date_str, date_value],..] :param size: 图片尺寸 :return: 图 """ if size is None: style = Style( width=960, height=420, background_color='#f0f0f0', ) else: style = Style( width=size['width'], height=size['height'], background_color='#f0f0f0', ) chart = HeatMap(title, **style.init_style) chart.add("", datas, is_calendar_heatmap=True, visual_text_color='#000', visual_range_text=['', ''], calendar_cell_size=['auto', 30], is_visualmap=True, calendar_date_range=year, visual_orient="horizontal", visual_pos="center", visual_top="80%", is_piecewise=True, ) chart.options['toolbox']['show'] = False return chart.render_embed()
def test_grid(): # grid_0 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, is_grid=True) bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%") bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%") line = Line("折线图示例", title_top="50%") attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] 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"], legend_top="50%") bar.grid(line.get_series(), grid_top="60%") bar.show_config() bar.render() # grid_1 v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter(width=1200, is_grid=True) scatter.add("散点图示例", v1, v2, grid_left="60%", legend_pos="70%") es = EffectScatter() es.add("动态散点图示例", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_pos="20%") scatter.grid(es.get_series(), grid_right="60%") scatter.show_config() scatter.render() # grid_2 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%", is_grid=True) bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%", grid_left="60%") bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%", grid_left="60%", legend_pos="80%") line = Line("折线图示例") attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] 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"], 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%") bar.grid(line.get_series(), grid_bottom="60%", grid_right="60%") bar.grid(scatter.get_series(), grid_top="60%", grid_left="60%") bar.grid(es.get_series(), grid_top="60%", grid_right="60%") bar.show_config() bar.render() # grid_3 line = Line("折线图示例", width=1200, is_grid=True) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], grid_right="65%") line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="45%") pie.add("", attr, v1, radius=[30, 55], legend_pos="65%", legend_orient='vertical') line.grid(pie.get_series(), grid_left="60%") line.show_config() line.render() # grid_4 line = Line("折线图示例", width=1200, is_grid=True) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], grid_right="60%") line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", grid_right="60%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] 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 线图示例", title_pos="60%") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, legend_pos="80%") line.grid(kline.get_series(), grid_left="55%") line.show_config() line.render() # grid_5 import random x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p" ] y_aixs = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday" ] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700, is_grid=True) heatmap.add("热力图直角坐标系", x_axis, y_aixs, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal', grid_bottom="60%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_top="50%") heatmap.grid(bar.get_series(), grid_top="60%") heatmap.show_config() heatmap.render()
[2, 5, 17.53], [2, 6, 18.56], [2, 7, 17.53], [3, 0, 17.57], [3, 1, 17.48], [3, 2, 17.54], [3, 3, 80.99], [3, 4, 18.53], [3, 5, 17.5], [3, 6, 85.1], [3, 7, 17.5], [4, 0, 18.53], [4, 1, 17.5], [4, 2, 85.1], [4, 3, 17.5], [4, 4, 17.56], [4, 5, 80.84], [4, 6, 17.53], [4, 7, 17.47], [5, 0, 84.27], [5, 1, 17.53], [5, 2, 18.56], [5, 3, 17.53], [5, 4, 18.53], [5, 5, 17.5], [5, 6, 85.1], [5, 7, 17.5], [6, 0, 18.53], [6, 1, 17.5], [6, 2, 85.1], [6, 3, 17.5], [6, 4, 84.27], [6, 5, 17.53], [6, 6, 18.56], [6, 7, 17.53], [7, 0, 18.53], [7, 1, 17.5], [7, 2, 85.1], [7, 3, 17.5], [7, 4, 17.56], [7, 5, 80.84], [7, 6, 17.53], [7, 7, 17.47]] x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p" ] y_axis = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday" ] heatmap = HeatMap("a heatmap", "this is subtitle") heatmap.add("GPUP2PBandWidth", GPUS, GPUS, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal', label_emphasis_textcolor='#000') heatmap.render("./MYheatMap2.html")
x_axis = copy(dfv[x_attr]) del dfv[x_attr] data = pde.df_to_hm_data(dfv) from pyecharts import HeatMap title = 'Profits of movie with different face number on poster and diversity' heatmap = HeatMap(title, title_pos='center') heatmap.add('', x_axis, dfv.columns, data, xaxis_interval=0, xaxis_label_textsize=10, xaxis_name_gap=30, yaxis_label_textsize=10, yaxis_name_gap=30, yaxis_rotate=0, is_visualmap=True, visual_range=[ np.nanmin([x[2] for x in data]), np.nanmax([x[2] for x in data]) ], visual_text_color="#000", visual_orient='horizontal') heatmap.render(title + '.html') ##################### step 4 ######################### # box-diagram # 01 attr column 1
def test_grid(): # grid_0 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, is_grid=True) bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%") bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%") line = Line("折线图示例", title_top="50%") attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] 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"], legend_top="50%") bar.grid(line.get_series(), grid_top="60%") bar.show_config() bar.render() # grid_1 v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] scatter = Scatter(width=1200, is_grid=True) scatter.add("散点图示例", v1, v2, grid_left="60%", legend_pos="70%") es = EffectScatter() es.add("动态散点图示例", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6, legend_pos="20%") scatter.grid(es.get_series(), grid_right="60%") scatter.show_config() scatter.render() # grid_2 attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%", is_grid=True) bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%", grid_left="60%") bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%", grid_left="60%", legend_pos="80%") line = Line("折线图示例") attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] 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"], 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%") bar.grid(line.get_series(), grid_bottom="60%", grid_right="60%") bar.grid(scatter.get_series(), grid_top="60%", grid_left="60%") bar.grid(es.get_series(), grid_top="60%", grid_right="60%") bar.show_config() bar.render() # grid_3 line = Line("折线图示例", width=1200, is_grid=True) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], grid_right="65%") line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="45%") pie.add("", attr, v1, radius=[30, 55], legend_pos="65%", legend_orient='vertical') line.grid(pie.get_series(), grid_left="60%") line.show_config() line.render() # grid_4 line = Line("折线图示例", width=1200, is_grid=True) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"], grid_right="60%") line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%", grid_right="60%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] value = [20, 40, 60, 80, 100, 120] 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 线图示例", title_pos="60%") kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, legend_pos="80%") line.grid(kline.get_series(), grid_left="55%") line.show_config() line.render() # grid_5 import random x_axis = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"] y_aixs = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap("热力图示例", height=700, is_grid=True) heatmap.add("热力图直角坐标系", x_axis, y_aixs, data, is_visualmap=True, visual_top="45%", visual_text_color="#000", visual_orient='horizontal', grid_bottom="60%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar("柱状图示例", title_top="52%") bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True, legend_top="50%") heatmap.grid(bar.get_series(), grid_top="60%") heatmap.show_config() heatmap.render()
liquid.add("Liquid", [0.6]) liquid.render() # ---------------------------------------------------------------------------- # heatmap import random from pyecharts import HeatMap x_axis = [ "12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"] y_axis = [ "Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"] data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] heatmap = HeatMap() heatmap.add("热力图直角坐标系", x_axis, y_axis, data, is_visualmap=True, visual_text_color="#000", visual_orient='horizontal') heatmap.render() def heatmap_2attr(df, attr1, attr2, func=len, value=None): if value==None: df2=df.groupby([attr1, attr2])[attr1].agg([func]) else: df2=df.groupby([attr1, attr2])[value].agg([func]) df2=df2.reset_index() x_axis = list(set(df2[attr1])) y_axis = list(set(df2[attr2])) data = [[x_axis.index(i), y_axis.index(j), df2.loc[(df2[attr1]==i) & (df2[attr2]==j), func.__name__]] for i in x_axis for j in y_axis]
from pyecharts import HeatMap import pandas as pd import numpy as np sim_frame = pd.read_csv('./data/philosophy.csv', index_col=0, encoding='utf8') names = list(sim_frame.index) data_array = np.round(np.array(sim_frame) ** 0.25 * 100, 0).astype(int) x_len, y_len = data_array.shape data = [[i, j, data_array[i][j]] for i in range(x_len) for j in range(y_len)] x_axis = names y_axis = names heatmap = HeatMap(title='哲学', subtitle='by @MiracleXYZ') heatmap.add( "相似度矩阵", x_axis, y_axis, data, is_visualmap=True, visual_text_color="#000", visual_orient='vertical', visual_range=[0, 100], visual_range_text=['低', '高'], visual_pos='left', label_pos='inside' ) heatmap.render('./data/philosophy_heatmap.html')