grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_right="50%")) .add(c, grid_opts=opts.GridOpts(pos_left="50%")) .add(c1, grid_opts=opts.GridOpts(pos_top="100%",pos_right="100%")) .add(wc, grid_opts=opts.GridOpts(pos_bottom="20%",pos_left="30%")) .add(a1, grid_opts=opts.GridOpts(pos_top="30%",pos_right="45%")) .render("垂直组合图_test.html") )将我们的折线图,饼图,柱状图,词云图,世界地图合成一个bi大屏,把世界地图放在大屏的右边位置,词云图放在左上位置,柱状图放在左下位置,饼图放在中间上面位置,折线图放在中间下面位置,整个大屏背景图换成黑色,请修改代码
时间: 2023-06-16 11:07:24 浏览: 234
simple_opts.sh:简单的 Bash 选项解析器
以下是修改后的代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar, Line, Pie, WordCloud, Grid
from pyecharts.faker import Faker
from pyecharts.globals import SymbolType
# 生成折线图
line = (
Line()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values(), is_smooth=True)
.add_yaxis("商家B", Faker.values(), is_smooth=True)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="折线图"))
)
# 生成饼图
pie = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_global_opts(title_opts=opts.TitleOpts(title="饼图"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
# 生成柱状图
bar = (
Bar()
.add_xaxis(Faker.days_attrs)
.add_yaxis("商家A", Faker.days_values)
.add_yaxis("商家B", Faker.days_values)
.set_global_opts(title_opts=opts.TitleOpts(title="柱状图"))
)
# 生成词云图
words = [("Sam S Club", 10000), ("Macys", 6181), ("Amy Schumer", 4386), ("Jurassic World", 4055), ("Charter Communications", 2467), ("Chick Fil A", 2244), ("Planet Fitness", 1868), ("Pitch Perfect", 1484), ("Express", 1112), ("Home", 865), ("Johnny Depp", 847), ("Lena Dunham", 582), ("Lewis Hamilton", 555), ("KXAN", 550), ("Mary Ellen Mark", 462), ("Farrah Abraham", 366), ("Rita Ora", 360), ("Serena Williams", 282), ("NCAA baseball tournament", 273), ("Point Break", 265)]
wc = (
WordCloud()
.add("", words, word_size_range=[20, 100])
.set_global_opts(title_opts=opts.TitleOpts(title="词云图"))
)
# 生成世界地图
from pyecharts.datasets import register_url
register_url("https://echarts-maps.github.io/echarts-countries-js/")
from pyecharts.charts import Map
from pyecharts.globals import ChartType
value = [95.1, 23.2, 43.3, 66.4, 88.5]
attr = ["China", "Canada", "Brazil", "Russia", "United States"]
map_chart = (
Map()
.add("世界地图", [list(z) for z in zip(attr, value)], "world")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="世界地图"),
visualmap_opts=opts.VisualMapOpts(max_=100),
)
)
# 将图表组合成大屏
grid = (
Grid(init_opts=opts.InitOpts(bg_color="#1f1f1f"))
.add(wc, grid_opts=opts.GridOpts(pos_top="10%", pos_left="5%"))
.add(bar, grid_opts=opts.GridOpts(pos_bottom="30%", pos_left="5%"))
.add(pie, grid_opts=opts.GridOpts(pos_top="10%", pos_right="5%"))
.add(line, grid_opts=opts.GridOpts(pos_bottom="30%", pos_right="5%"))
.add(map_chart, grid_opts=opts.GridOpts(pos_bottom="10%", pos_right="5%"))
.render("垂直组合图_test.html")
)
```
主要修改是在 `Grid` 初始化时增加了 `bg_color` 参数来设置大屏的背景颜色,并且把每个图表在 `GridOpts` 中指定的位置进行了调整。
阅读全文