用 Pyecharts 制作炫酷的可视化大屏
时间:2021-10-20 16:16:35
手机看文章
扫描二维码
随时随地手机看文章
[导读]作者|俊欣来源|关于数据分析与可视化前两篇Pyecharts的文章来帮我们简单的梳理了一下可以用Pyecharts来绘制哪些图表之后,本篇文章我们用pyecharts里面的一些组件,将绘制的图表都组合起来首先Grid组件首先介绍Pyecharts模块当中的Grid组件,使用Gri...
作者 | 俊欣来源 | 关于数据分析与可视化前两篇Pyecharts的文章来帮我们简单的梳理了一下可以用Pyecharts来绘制哪些图表之后,本篇文章我们用pyecharts里面的一些组件,将绘制的图表都组合起来
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_bottom="60%")) .add(line, grid_opts=opts.GridOpts(pos_top="50%")) .render("水平组合图_test.html"))
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_left="60%")) .add(line, grid_opts=opts.GridOpts(pos_right="50%")) .render("垂直组合图_test.html"))
map = ( Map() .add("商家1", [list(z) for z in zip(Faker.provinces, Faker.values())], "china") .set_global_opts(title_opts=opts.TitleOpts(title="地图-基本示例")))
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_top="50%", pos_right="75%")) .add(map, grid_opts=opts.GridOpts(pos_left="60%")) .render("地图 直方图.html"))
bar = ( Bar() .add_xaxis(Faker.provinces) .add_yaxis("商家A", v1) .add_yaxis("商家B", v2) .extend_axis( yaxis=opts.AxisOpts( axislabel_opts=opts.LabelOpts(formatter="{value} 个"), interval=20 ) ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="Overlap-bar line"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} 个")), ))
line = Line().add_xaxis(Faker.provinces).add_yaxis("商家C", v3, yaxis_index=1)bar.overlap(line)bar.render("直方图 折线图Overlap.html")
bar.overlap(line)grid = Grid()grid.add(bar, opts.GridOpts(pos_left="5%", pos_right="20%"), is_control_axis_index=True)grid.render("test.html")
def line_markpoint() -> Line: c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis( "商家A", Faker.values(), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")]), ) .set_global_opts(title_opts=opts.TitleOpts(title="折线图")) ) return c
def pie_rosetype() -> Pie: v = Faker.choose() c = ( Pie() .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["25%", "50%"], rosetype="radius", label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title="饼图-玫瑰图示例")) ) return c tab = Tab()tab.add(bar_datazoom_slider(), "直方图")tab.add(line_markpoint(), "折线图")tab.add(pie_rosetype(), "饼图")tab.render("tab_base.html")
def line_markpoint() -> Line: c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis( "商家A", Faker.values(), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")]), ) .set_global_opts(title_opts=opts.TitleOpts(title="折线图")) ) return c
def pie_rosetype() -> Pie: v = Faker.choose() c = ( Pie() .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["25%", "50%"], rosetype="radius", label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title="饼图-玫瑰图示例")) ) return c page = Page(layout=Page.SimplePageLayout)page.add( bar_datazoom_slider(), line_markpoint(), pie_rosetype(),)page.render("page_simple_layout.html")
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_bottom="60%")) .add(line, grid_opts=opts.GridOpts(pos_top="50%")) .render("水平组合图_test.html"))
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_left="60%")) .add(line, grid_opts=opts.GridOpts(pos_right="50%")) .render("垂直组合图_test.html"))
map = ( Map() .add("商家1", [list(z) for z in zip(Faker.provinces, Faker.values())], "china") .set_global_opts(title_opts=opts.TitleOpts(title="地图-基本示例")))
grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_top="50%", pos_right="75%")) .add(map, grid_opts=opts.GridOpts(pos_left="60%")) .render("地图 直方图.html"))
bar = ( Bar() .add_xaxis(Faker.provinces) .add_yaxis("商家A", v1) .add_yaxis("商家B", v2) .extend_axis( yaxis=opts.AxisOpts( axislabel_opts=opts.LabelOpts(formatter="{value} 个"), interval=20 ) ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="Overlap-bar line"), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} 个")), ))
line = Line().add_xaxis(Faker.provinces).add_yaxis("商家C", v3, yaxis_index=1)bar.overlap(line)bar.render("直方图 折线图Overlap.html")
bar.overlap(line)grid = Grid()grid.add(bar, opts.GridOpts(pos_left="5%", pos_right="20%"), is_control_axis_index=True)grid.render("test.html")
def line_markpoint() -> Line: c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis( "商家A", Faker.values(), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")]), ) .set_global_opts(title_opts=opts.TitleOpts(title="折线图")) ) return c
def pie_rosetype() -> Pie: v = Faker.choose() c = ( Pie() .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["25%", "50%"], rosetype="radius", label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title="饼图-玫瑰图示例")) ) return c tab = Tab()tab.add(bar_datazoom_slider(), "直方图")tab.add(line_markpoint(), "折线图")tab.add(pie_rosetype(), "饼图")tab.render("tab_base.html")
def line_markpoint() -> Line: c = ( Line() .add_xaxis(Faker.choose()) .add_yaxis( "商家A", Faker.values(), markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")]), ) .set_global_opts(title_opts=opts.TitleOpts(title="折线图")) ) return c
def pie_rosetype() -> Pie: v = Faker.choose() c = ( Pie() .add( "", [list(z) for z in zip(v, Faker.values())], radius=["30%", "75%"], center=["25%", "50%"], rosetype="radius", label_opts=opts.LabelOpts(is_show=False), ) .set_global_opts(title_opts=opts.TitleOpts(title="饼图-玫瑰图示例")) ) return c page = Page(layout=Page.SimplePageLayout)page.add( bar_datazoom_slider(), line_markpoint(), pie_rosetype(),)page.render("page_simple_layout.html")