在pyecharts中添加table,from pyecharts.charts import Table这个语句是无法实现的,你还有其他办法吗?
时间: 2023-06-11 20:05:50 浏览: 137
可以使用pyecharts_snapshot包中的Echarts类来创建一个表格。代码示例如下:
```python
from snapshot_selenium import snapshot as driver
from pyecharts import options as opts
from pyecharts.charts import Bar, Table
from pyecharts.render import make_snapshot
table_data = [
['City name', 'Area', 'Population', 'Annual Rainfall'],
['Brisbane', '5905', '1857594', '1146.4'],
['Perth', '5386', '1554769', '869.4'],
['Gold Coast', '1334', '591473', '1386.6'],
['Sydney', '2058', '4336374', '1214.8'],
['Melbourne', '1566', '3806092', '646.9'],
['Adelaide', '1295', '1148586', '600.5'],
['Bundaberg', '9215', '100380', '1152.7'],
['Rockhampton', '2358', '77625', '933.3'],
['Cairns', '1507', '166875', '1999.4'],
]
table = Table()
table.add(
headers=table_data[0],
rows=table_data[1:]
)
bar = (
Bar()
.add_xaxis(["Brisbane", "Perth", "Gold Coast", "Sydney", "Melbourne", "Adelaide", "Bundaberg", "Rockhampton", "Cairns"])
.add_yaxis("Population", [1857594, 1554769, 591473, 4336374, 3806092, 1148586, 100380, 77625, 166875])
.set_global_opts(title_opts=opts.TitleOpts(title="Australian Cities"))
)
make_snapshot(driver, bar.render(), "bar.png")
make_snapshot(driver, table.render(), "table.png")
```
运行后会生成两个图像文件,一个是柱状图,一个是表格。这个例子使用了pyecharts_snapshot和snapshot_selenium包来生成图像,所以你需要安装这两个包。
阅读全文