from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.faker import Faker c = ( Bar() .add_xaxis(Faker.choose()) .add_yaxis("商家A", Faker.values()) .add_yaxis("商家B", Faker.values()) .set_global_opts( title_opts=opts.TitleOpts(title="Bar-Brush示例", subtitle="我是副标题"), brush_opts=opts.BrushOpts(), ) .render("bar_with_brush.html") )这个代码如何修改,让其在pycharm中显示出可视化图形来
时间: 2024-03-04 09:48:48 浏览: 148
在PyCharm中显示可视化图形,需要在代码中添加以下两行:
```python
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot as driver
```
并在代码末尾添加以下代码:
```python
make_snapshot(driver, c.render(), "bar_with_brush.png")
```
这将生成一个名为"bar_with_brush.png"的图像文件,其中包含可视化图表。
完整修改后的代码如下:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot as driver
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Brush示例", subtitle="我是副标题"),
brush_opts=opts.BrushOpts(),
)
)
make_snapshot(driver, c.render(), "bar_with_brush.png")
```
阅读全文