一、【组合图表: Tab选项卡多图】示例代码如下:
# 【组合图表: Tab选项卡多图】
# 组合图表,也是一种特殊的图表类型
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line, Page, Tab
from pyecharts.faker import Faker
bar = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(title_opts=opts.TitleOpts(title="Grid-Bar"))
)
line = (
Line()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"),
# 通过联合调整pos_bottom, pos_top, pos_left, pos_right这四个参数,可以精细布局图例在整张画布中的位置
legend_opts=opts.LegendOpts(pos_bottom="30%",pos_top="65%",
pos_left="10%",pos_right="75%",
textstyle_opts = opts.TextStyleOpts(font_size=3),
),
)
)
line1 = (
Line()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"),
legend_opts=opts.LegendOpts(pos_top="48%"),
)
)
line2 = (
Line()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Grid-Line", pos_top="48%"),
legend_opts=opts.LegendOpts(pos_top="48%"),
)
)
# 【组合图表: Tab选项卡多图】
tab = Tab()
tab.add(bar, "bar")
tab.add(line, "line")
tab.add(line1, "line1")
tab.add(line2, "line2")
tab.render_notebook()
二、图表展示