- """
- author:少校
- create Time:2025/2/28 14:02
- 越努力越幸运
- """
- from pyecharts.charts import Bar, Line, Pie, Map, Grid, Page
- from pyecharts import options
- from pyecharts.globals import ThemeType
-
- # 1. 先准备需要组合的多个单独的图表(图表不需要制图)
- # 图1
- bar = Bar()
- bar.add_xaxis(['数据分析', '物联网', '云计算', '鸿蒙开发', '网络安全'])
- bar.add_yaxis('招生人数', [345, 403, 270, 185, 300])
- bar.add_yaxis('应届生人数', [250, 120, 50, 80, 180])
- bar.set_global_opts(
- title_opts=options.TitleOpts(
- title='XXX公司2024上半年数据看板',
- pos_left='500px'
- ),
- legend_opts=options.LegendOpts(is_show=False)
- )
-
- # 图2
- line = Line()
- line.add_xaxis(['1月', '2月', '3月', '4月', '5月', '6月'])
- line.add_yaxis('销售额', [89, 102, 77, 65, 120, 50])
- line.add_yaxis('成本', [40, 52, 33, 26, 59, 10])
- line.set_global_opts(
- title_opts=options.TitleOpts(is_show=False),
- legend_opts=options.LegendOpts(is_show=False)
- )
-
- # 图3
- pie = Pie()
- pie.add(
- '销量',
- [('华为', 290000), ('小米', 329870), ('Apple', 128700), ('Vivo', 98760), ('Oppo', 109870)],
- radius=(50, 200), # (内半径, 外半径)
- rosetype='radius', # 让外半径的值根据占比自动调整(制作不规则饼图)
- center=('950px', '800px')
- )
- pie.set_global_opts(
- title_opts=options.TitleOpts(is_show=False),
- legend_opts=options.LegendOpts(is_show=False)
- )
-
- # 图4
- map1 = Map()
- # 2. 添加数据
- map1.add(
- '人均GDP',
- [('四川省', 77315), ('北京市', 228011), ('上海市', 216834),
- ('湖南省', 57890), ('青海省', 49876), ('广东省', 139080), ('山西省', 68905),
- ('内蒙古自治区', 85621)],
- zoom=0.5, # 默认大小为原地图的1.5倍
- max_scale_limit=0.5, # 缩放最大倍数为3
- min_scale_limit=0.5, # 缩放最小倍数为0.7
- center=('145px', '20px')
-
- )
- map1.set_global_opts(
- title_opts=options.TitleOpts(is_show=False),
- legend_opts=options.LegendOpts(is_show=False)
- )
-
- # 2. 创建Grid对象(大盒子)
- grid = Grid(
- init_opts=options.InitOpts(
- width='1500px',
- height='2000px',
- theme=ThemeType.LIGHT
- )
- )
- grid.add(bar, grid_opts=options.GridOpts(
- pos_left=50,
- pos_top=20,
- width=600,
- height=400
- ))
-
- grid.add(line, grid_opts=options.GridOpts(
- pos_left=710,
- pos_top=20,
- width=600,
- height=400
- ))
-
- grid.add(map1, grid_opts=options.GridOpts())
- grid.add(pie, grid_opts=options.GridOpts())
-
- grid.render('charts/组合3.html')
10.图表组合2
本节2604字(读完预计:分秒)2025-03-03 17:21:31