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 heat_corr(): # 将上面的相关系数矩阵处理一下 value = [[0, 0, 1.00], [0, 1, 0.04], [0, 2, -0.07], [0, 3, -0.05], [0, 4, -0.28], [1, 0, 0.04], [1, 1, 1.00], [1, 2, 0.13], [1, 3, 0.40], [1, 4, 0.33], [2, 0, -0.07], [2, 1, 0.13], [2, 2, 1.00], [2, 3, 0.25], [2, 4, 0.52], [3, 0, -0.05], [3, 1, 0.40], [3, 2, 0.25], [3, 3, 1.00], [3, 4, 0.68], [4, 0, -0.28], [4, 1, 0.33], [4, 2, 0.52], [4, 3, 0.68], [4, 4, 1.00]] c = (HeatMap(init_opts=opts.InitOpts( theme=ThemeType.PURPLE_PASSION)).add_xaxis([ '评论数', '人均价格', '口味评分', '环境评分', '服务评分' ]).add_yaxis( "", ['评论数', '人均价格', '口味评分', '环境评分', '服务评分'], value, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="评论数,人均价格,口味评分,环境评分,服务评分相关性热力图", pos_left='center'), visualmap_opts=opts.VisualMapOpts(is_show=False, min_=-1, max_=1), )) c.render('相关性热力图.html') return c
def _plot_monthly_returns(self, stats): """ Plots the monthly returns heatmap """ returns = stats['returns'] monthly_ret = perf.aggregate_returns(returns, 'monthly') monthly_ret = monthly_ret.unstack() monthly_ret = np.round(monthly_ret, 3) monthly_ret = monthly_ret.fillna(0) * 100 row_count = len(monthly_ret) month = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] values = [] for i in range(12): for j in range(row_count): v = monthly_ret.iloc[j, i] s = "%.3f" % v values.append([i, j, round(v, 3), s]) c = (HeatMap().add_xaxis(month).add_yaxis("", list( monthly_ret.index), values).set_global_opts( title_opts=opts.TitleOpts(title="Monthly Returns (%)"), visualmap_opts=opts.VisualMapOpts( min_=min(values, key=lambda x: x[2])[2], max_=max(values, key=lambda x: x[2])[2]), )) return c
def heat_corr(x_data, y_data, val_list): """绘制【描述"评论数", "人均价格", "口味评分", "环境评分", "服务评分"这些指标之间相关程度】的热力图 6.1 设置主题"purple-passion"; 6.2 图例系列名为空,数值标签位居色块中央; 6.3 标题"价格口碑等相关性" 6.4 隐藏视觉映射配置项传入参数,但仍指定最小和最大映射值min_=-1, max_=1; 6.5 return返回c; :param x_data: "评论数", "人均价格", "口味评分", "环境评分", "服务评分"指标 :param y_data: 也是"评论数", "人均价格", "口味评分", "环境评分", "服务评分"指标 :param val_list: 热力矩阵各个色块的取值 :return: 绘制好的热力图对象 """ c = (HeatMap(init_opts=opts.InitOpts( theme=ThemeType.PURPLE_PASSION)).set_global_opts( title_opts=opts.TitleOpts(title="价格口碑等相关性"), visualmap_opts=opts.VisualMapOpts( is_show=False, min_=-1, max_=1)).add_xaxis(xaxis_data=x_data).add_yaxis( series_name="", yaxis_data=y_data, value=val_list, label_opts=opts.LabelOpts(position="inside"))) return c
def effectscattere_symbol() -> 'html': df = pd.read_csv('data2.csv',encoding = 'utf8', index_col="名称") 省 = list(df.loc["省"].values)[-24:] 数量 = list(df.loc["数量"].values)[-24:] value = [[i, j, random.randint(0, 80)] for i in range(24) for j in range(24)] c = ( HeatMap() .add_xaxis(省) .add_yaxis("数量", 数量, value) .set_global_opts( title_opts=opts.TitleOpts(title="各省Python相关岗位数量"), visualmap_opts=opts.VisualMapOpts(), ) ) c.render("./templates/effectscatter_symbol.html") with open("./templates/effectscatter_symbol.html", encoding="utf8", mode="r") as f: sym = "".join(f.readlines()) return render_template('python_effectscatter_symbol.html', the_sym=sym, ) 1 data_pie1 = data_pie.T.to_html() pie1_list = [num for num in data_pie['分类']] labels = [index for index in data_pie.index]
def pyecharts_heatmap(to_arr, chip_file_name, category, max_value, min_value, lower_q, sequence_flag): values = [[i, j, round(to_arr[i][j], 3)] for i in range(40) for j in range(40)] print(values) c = (HeatMap( init_opts=opts.InitOpts(width="1200px", height="800px")).add_xaxis( [i for i in range(1, 41)]).add_yaxis( category, [i for i in range(1, 41)], values, label_opts=opts.LabelOpts(is_show=False, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title=sequence_flag), visualmap_opts=opts.VisualMapOpts( is_show=True, min_=min_value, max_=max_value, item_height=30, item_width=15, ), ).render("heatmap_with_label_show.html")) import webbrowser webbrowser.open( "file:///D:/GUI/MGI Engineering Tools/utils/heatmap_with_label_show.html" )
def heatmap_base() -> HeatMap: value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = (HeatMap().add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-基本示例"), visualmap_opts=opts.VisualMapOpts(), )) return c
def plot(self): self.chart = HeatMap(init_opts=opts.InitOpts(page_title=self.title)) # load data self.chart.add_xaxis(self.data_x) self.chart.add_yaxis(self.zaxis_name, self.data_y, self.heat_map) self.chart.set_global_opts( title_opts=opts.TitleOpts(title=self.title), xaxis_opts=opts.AxisOpts(name=self.xaxis_name, name_location='end', name_gap=15), yaxis_opts=opts.AxisOpts(name=self.yaxis_name, name_location='end', name_gap=15), visualmap_opts=opts.VisualMapOpts(max_=self.max_value, min_=self.min_value)) return self
def test_heatmap_base(): value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = (HeatMap().add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value).set_global_opts(visualmap_opts=opts.VisualMapOpts())) eq_(c.theme, "white") eq_(c.renderer, "canvas") c.render()
def test_heatmap_base(fake_writer): value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = (HeatMap().add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value).set_global_opts(visualmap_opts=opts.VisualMapOpts())) c.render() _, content = fake_writer.call_args[0] assert_equal(c.theme, "white") assert_equal(c.renderer, "canvas")
def draw(): value = [[i, j, Data[i][j]] for i in range(50) for j in range(50)] c = ( HeatMap() .add_xaxis(["ID:"+str(i) for i in range(50)]) .add_yaxis("Regularized Similarity",["ID:"+str(i) for i in range(50)],value) .set_global_opts( title_opts=opts.TitleOpts(title="样本相关度可视化"), visualmap_opts=opts.VisualMapOpts(), ) ) return c
class HeatMapChart(base_chart.BaseChart): chart = None zaxis_name = None data_x = [] data_y = [] heat_map = [] max_value = 0 min_value = 0 def __init__(self, title, xaxis_name, yaxis_name, zaxis_name): base_chart.BaseChart.__init__(self, title, xaxis_name, yaxis_name) self.zaxis_name = zaxis_name def clear(self): self.data_x.clear() self.data_y.clear() self.heat_map.clear() def set_data(self, **data): if ('x' in data) & ('y' in data) & ('map' in data): self.data_x = data['x'] self.data_y = data['y'] self.to_echarts_map(data['map']) return self def show(self): return self.chart def to_echarts_map(self, map) -> []: self.max_value = map[0][0] self.min_value = map[0][0] for i in range(len(map)): for j in range(len(map[i])): if self.max_value < map[i][j]: self.max_value = map[i][j] if self.min_value > map[i][j]: self.min_value = map[i][j] self.heat_map.append([j, i, map[i][j]]) return self.heat_map def plot(self): self.chart = HeatMap(init_opts=opts.InitOpts(page_title=self.title)) # load data self.chart.add_xaxis(self.data_x) self.chart.add_yaxis(self.zaxis_name, self.data_y, self.heat_map) self.chart.set_global_opts( title_opts=opts.TitleOpts(title=self.title), xaxis_opts=opts.AxisOpts(name=self.xaxis_name, name_location='end', name_gap=15), yaxis_opts=opts.AxisOpts(name=self.yaxis_name, name_location='end', name_gap=15), visualmap_opts=opts.VisualMapOpts(max_=self.max_value, min_=self.min_value)) return self
def heatmap_with_label_show() -> HeatMap: value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = (HeatMap().add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), )) return c
def corr_plot(data: list): from pyecharts import options as opts from pyecharts.charts import HeatMap from pyecharts.faker import Faker corr = (HeatMap().add_xaxis('series0').add_yaxis( "series1", data, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), ).render("相关性图.html"))
def v_correlation(self, end=yesterdayobj(), vopts=None): """ 各基金净值的相关程度热力图可视化 :param end: string or object of date, the end date of the line :returns: pyecharts.charts.Heatmap.render_notebook 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_xaxis(x_axis) heatmap.add_yaxis(series_name="相关性", yaxis_data=x_axis, value=data) if vopts is None: vopts = heatmap_opts heatmap.set_global_opts(**vopts) return heatmap.render_notebook()
def heat_plot(data): n, m = data.shape x, y = np.arange(0, n, 1), np.arange(0, m, 1) x, y = np.meshgrid(x, y, indexing='ij') z = data.values.flatten() x = m - 1 - x _data = list(zip(y.flatten(), x.flatten(), z)) _data = [[int(d[0]), int(d[1]), np.round(d[2], 4)] for d in _data] h = ( HeatMap( init_opts=opts.InitOpts(width="1000px", height="300px")).add_xaxis( xaxis_data=data.columns.astype(str).tolist()).add_yaxis( series_name="", yaxis_data=data.index.astype(str).tolist()[::-1], value=_data, label_opts=opts.LabelOpts(position='inside', is_show=True, font_size=15), ).set_series_opts().set_global_opts( # toolbox_opts=opts.ToolboxOpts(is_show=True), legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, ), xaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), yaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), visualmap_opts=opts.VisualMapOpts(min_=z.min(), max_=z.max(), is_calculable=True, orient="vertical", pos_left="left"), toolbox_opts=opts.ToolboxOpts( is_show=True, feature=opts.ToolBoxFeatureOpts( save_as_image=opts.ToolBoxFeatureSaveAsImageOpts( background_color='white', connected_background_color="white", pixel_ratio=2, name="pic", ), )), )) return h
def heatOutPortTime(self, data) -> HeatMap: # 每周出港航班按小时热力图 out_port_time_heat = (HeatMap( init_opts=opts.InitOpts(width='1000px', height='500px')).add_xaxis( data[0]).add_yaxis("", data[1], data[2]).set_global_opts( title_opts=opts.TitleOpts( title='本周出港航班时间热力图', title_textstyle_opts=opts.TextStyleOpts(font_size=20), subtitle='{} [数据来源:ctrip.com]'.format(self.today_ymd)), visualmap_opts=opts.VisualMapOpts(type_='color', min_=0, max_=1000), )) return out_port_time_heat
def heatmap_car() -> HeatMap: x = ['宝马', '法拉利', '奔驰', '奥迪', '大众', '丰田', '特斯拉'] y = ['中国','日本','南非','澳大利亚','阿根廷','阿尔及利亚','法国','意大利','加拿大'] value = [[i, j, random.randint(0, 100)] for i in range(len(x)) for j in range(len(y))] c = ( HeatMap() .add_xaxis(x) .add_yaxis("销量", y, value) .set_global_opts( title_opts=opts.TitleOpts(title="HeatMap"), visualmap_opts=opts.VisualMapOpts(), ) ) return c
def heatmap_base() -> HeatMap: value = inputData # value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = ( HeatMap() .add_xaxis(SidesList) .add_yaxis("HeatMap", USRegionOrder, value, label_opts=opts.LabelOpts(is_show=True, position="inside",interval= 0) ) .set_global_opts( #title_opts=opts.TitleOpts(title="HeatMap-基本示例"), visualmap_opts=opts.VisualMapOpts(pos_left = "right"), # axis =opts.AxisOpts(offset=100,is_show= False,name_gap = 0, interval = 200) ) ) return c
def heat_map(data: List[dict], x_label: List[str] = None, y_label: List[str] = None, title: str = "热力图", width: str = "900px", height: str = "680px") -> HeatMap: """绘制热力图 :param data: 用于绘制热力图的数据,示例如下 [{'x': '0hour', 'y': '0day', 'heat': 11}, {'x': '0hour', 'y': '1day', 'heat': 40}, {'x': '0hour', 'y': '2day', 'heat': 38}, {'x': '0hour', 'y': '3day', 'heat': 36}, {'x': '0hour', 'y': '4day', 'heat': 11}] :param x_label: x轴标签 :param y_label: y轴标签 :param title: 图表标题 :param width: 图表宽度 :param height: 图表高度 :return: 图表 """ value = [[s['x'], s['y'], s['heat']] for s in data] heat = [s['heat'] for s in data] if not x_label: x_label = sorted(list(set([s['x'] for s in data]))) if not y_label: y_label = sorted(list(set([s['y'] for s in data]))) vis_map_opts = opts.VisualMapOpts(pos_left="90%", pos_top="20%", min_=min(heat), max_=max(heat)) title_opts = opts.TitleOpts(title=title) init_opts = opts.InitOpts(page_title=title, width=width, height=height) dz_inside = opts.DataZoomOpts(False, "inside", xaxis_index=[0], range_start=80, range_end=100) dz_slider = opts.DataZoomOpts(True, "slider", xaxis_index=[0], pos_top="96%", pos_bottom="0%", range_start=80, range_end=100) legend_opts = opts.LegendOpts(is_show=False) hm = HeatMap(init_opts=init_opts) hm.add_xaxis(x_label) hm.add_yaxis("heat", y_label, value, label_opts=opts.LabelOpts(is_show=True, position="inside")) hm.set_global_opts(title_opts=title_opts, visualmap_opts=vis_map_opts, legend_opts=legend_opts, xaxis_opts=opts.AxisOpts(grid_index=0), datazoom_opts=[dz_inside, dz_slider]) return hm
def _timeline(perf, name=""): tl = Timeline(init_opts=opts.InitOpts(width="1000px", height="400px")) series = perf.index.get_level_values(0).unique() if isinstance( perf.index, pd.MultiIndex) else [name] for i, _w in enumerate(series): _data = perf.loc[_w] if isinstance(perf.index, pd.MultiIndex) else perf n, m = _data.shape x, y = np.arange(0, n, 1), np.arange(0, m, 1) x, y = np.meshgrid(x, y, indexing='ij') z = _data.values.flatten() data = list(zip(y.flatten(), x.flatten(), z)) data = [[int(d[0]), int(d[1]), np.round(d[2], 4)] for d in data] h = (HeatMap( init_opts=opts.InitOpts(width="1000px", height="300px")).add_xaxis( xaxis_data=_data.columns.astype(str).tolist()).add_yaxis( series_name="", yaxis_data=_data.index.astype(str).tolist(), value=data, label_opts=opts.LabelOpts(position='inside', is_show=True), ).set_series_opts().set_global_opts( toolbox_opts=opts.ToolboxOpts(is_show=True), legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, ), xaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), yaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), visualmap_opts=opts.VisualMapOpts(min_=z.min(), max_=z.max(), is_calculable=True, orient="vertical", pos_left="left"), )) tl.add(h, "{}".format(_w)) if not isinstance(perf.index, pd.MultiIndex): tl.add_schema(is_timeline_show=False) return tl
def plot_confusion_by_heat_map(matrix, xaxis, yaxis, fig_name): """ drawing confusion matrix with heatmap :param matrix: confusion matrix :param xaxis: x axis label :param yaxis: y axis label :return: """ from pyecharts import options as opts from pyecharts.charts import HeatMap (row, col) = matrix.shape data = [] for i in range(row): for j in range(col): data.append([i, j, np.float32(matrix[i][j]).item()]) heat_map = (HeatMap().add_xaxis(xaxis).add_yaxis( 'f1_score', yaxis, data).set_global_opts( title_opts=opts.TitleOpts(title=fig_name), visualmap_opts=opts.VisualMapOpts( range_color=['#121122', 'rgba(3,4,5,0.4)', 'red']), )) heat_map.render(path='../chart/' + fig_name + '.html')
splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts( is_show=True, color='black', width=10, )), ) c = ( HeatMap(init_opts=opts.InitOpts(bg_color='black', )).add_xaxis( xdata).add_yaxis( "月份", ydata, data, ).set_global_opts( title_opts=opts.TitleOpts(), legend_opts=opts.LegendOpts(is_show=False, ), visualmap_opts=opts.VisualMapOpts( min_=1, max_=158, is_calculable=True, orient='horizontal', pos_left='center', pos_bottom='-1%', range_color=['#C0F1F4', '#60BDCB', '#316870', '#EA7552'], textstyle_opts=opts.TextStyleOpts(color='#A3C7E7')), tooltip_opts=opts.TooltipOpts(position='top'), xaxis_opts=axisOpts, yaxis_opts=axisOpts, ).set_series_opts(zlevel=-1 # 这是一个重要属性,设置图层 ).render("sale-heatmap.html"))
data.append([x, y, cn[x][y]]) (HeatMap(init_opts=opts.InitOpts(width="1440px", height="720px")).add_xaxis( xaxis_data=country).add_yaxis( series_name="前百在榜数", yaxis_data=years, value=data, label_opts=opts.LabelOpts(is_show=True, color="#fff", position="inside", horizontal_align="50%"), ).set_series_opts().set_global_opts( legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), yaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), visualmap_opts=opts.VisualMapOpts(min_=0, max_=10, is_calculable=True, orient="horizontal", pos_left="center"), ).render("不同国家前百在榜大学数.html")) # 平行坐标图代码
for i in range(4, 10): kw_counts_by_score[i] = pd.read_csv(r'.\data_set\{0}_movie_keywords.csv'.format(i)) kw_percentage_df = pd.DataFrame([], columns=list(range(4, 10)), index=kw_counts_by_score[9]['kw'][:10]) # 将数据写入空表 for i in range(4, 10): kw_df = kw_counts_by_score[i] kw_df = kw_df[kw_df['kw'].isin(kw_percentage_df.index)] kw_percentage_df[i] = pd.Series(list(kw_df['percentage']), index=kw_df['kw']) # 用0替换NAN,否则无法计算 kw_percentage_df.fillna(0, inplace=True) # 建立有三个元素的列表,作为绘制的数据 data = [] i = 0 for index in kw_percentage_df.index: j = 0 for column in kw_percentage_df.columns: data.append([j, i, kw_percentage_df[column][index] * 100]) j += 1 i += 1 # 绘制热力图 heatmap = HeatMap() heatmap.add_xaxis(list(kw_percentage_df.columns)) heatmap.add_yaxis('电影评论关键词热力图', list(kw_percentage_df.index), data) heatmap.set_global_opts(visualmap_opts=opts.VisualMapOpts(min_=0, max_=10, orient='horizontal')) heatmap.render('comment_heatmap.html')
def bar_base() -> Bar: path = "Video_Monitor/video_list.json" ztstatus = Readjson(path) now = datetime.datetime.now() zsf = now.minute % 10 time = [] if zsf > 0: dqzsj = now - datetime.timedelta(minutes=zsf) else: dqzsj = now for j in range(720): tssj1 = dqzsj - datetime.timedelta(minutes=1 * (j - 1)) tssj = tssj1.strftime('%Y-%m-%d %H:%M') time.insert(0, tssj) # app.logger.info(time) data = select(time[0]) # app.logger.info(data) name = ztstatus[1][0] newData = [] for value in range(len(data)): x = time.index(data[value].get('testtime')) y = name.index(data[value].get('ztname')) z = data[value].get('ztstatus') newData.append([x, y, z]) data = [[d[0], d[1], d[2] or "-"] for d in newData] c = ( HeatMap().add_xaxis(xaxis_data=time).add_yaxis( series_name="详情", yaxis_data=name, value=data, label_opts=opts.LabelOpts(is_show=True, color="#fff", position="bottom", horizontal_align="100%"), ).set_series_opts( label_opts=opts.LabelOpts(is_show=True), minortick_opts=opts.MinorTickOpts(is_show=True, split_number=8), minorsplitkine_opts=opts.MinorSplitLineOpts(is_show=True)). set_global_opts( # tooltip_opts=opts.TooltipOpts(formatter='{a},{@time}:\n,{@[0]}'), # axistick_opts=opts.AxisTickOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(is_show=True, is_piecewise=True, pos_left='center', orient='horizontal', pieces=[{ "value": 200, "label": '正常', "color": 'green' }, { "value": 404, "label": '异常', "color": 'Orange' }, { "value": 408, "label": '超时', "color": 'grey' }]), legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts( type_="category", boundary_gap=True, axistick_opts=opts.AxisTickOpts(is_align_with_label=True), splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(opacity=1)), minor_split_line_opts=opts.MinorSplitLineOpts(is_show=True), ), yaxis_opts=opts.AxisOpts( type_="category", boundary_gap=True, axistick_opts=opts.AxisTickOpts(is_align_with_label=True), splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(opacity=1)), ), )) return c
( HeatMap() .add_xaxis(xaxis_data=hours) .add_yaxis( series_name="Punch Card", yaxis_data=days, value=data, label_opts=opts.LabelOpts( is_show=True, color="#fff", position="bottom", horizontal_align="50%" ), ) .set_series_opts() .set_global_opts( legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), yaxis_opts=opts.AxisOpts( type_="category", splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), ), visualmap_opts=opts.VisualMapOpts( min_=0, max_=10, is_calculable=True, orient="horizontal", pos_left="center" ), ) .render("heatmap_on_cartesian.html") )
] parallel_data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"], [20, 120, 60, "Excellent"]] # init_opts=opts.InitOpts(width="800px",height="300px") parallel = Parallel(init_opts=opts.InitOpts(width="800px", height="300px")) parallel.add_schema(parallel_axis) parallel.add(series_name="Related Indexes", data=parallel_data, linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5)) liquid = Liquid(init_opts=opts.InitOpts(width="300px", height="300px")) liquid.add("liquid", [0.6, 0.7, 0.3]) liquid.set_global_opts(title_opts=opts.TitleOpts(title="Basic Example")) heatmap_data = [[i, j, random.randint(0, 50)] for i in range(7) for j in range(7)] heatmap = HeatMap() heatmap.add_xaxis(Faker.week) heatmap.add_yaxis( "相关表", Faker.week, heatmap_data, label_opts=opts.LabelOpts(is_show=True, position="inside"), ) heatmap.set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), )
import random from pyecharts import options as opts from pyecharts.charts import HeatMap from pyecharts.faker import Faker value = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)] c = (HeatMap().add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), ).render("heatmap_with_label_show.html"))
from pyecharts.charts import HeatMap import datetime import random import os, sys os.chdir(sys.path[0]) # 改变目录 begin = datetime.date(2018, 1, 1) #设置起始日期 end = datetime.date(2019, 12, 31) #设置终止日期 data = [ [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)] #设置日期间隔,步数范围 for i in range((end - begin).days + 1) ] heatmap_k = HeatMap('2018年') heatmap_k.add('', data, is_calendar_heatmap=True, visual_range=[1000, 25000], is_visualmap=True, calendar_data_range=[data[0][0], data[-1][0]], visual_orient='horizontal', visual_pos='center', visual_top='90%', calendar_cell_size=[25, 35]) heatmap_k.render('heatmap.html')