如何使用pyecharts画折线图
时间: 2023-07-05 12:04:57 浏览: 89
使用Pyecharts画折线图的步骤如下:
1. 安装Pyecharts库
```
pip install pyecharts
```
2. 导入折线图类
```
from pyecharts.charts import Line
```
3. 创建一个折线图实例
```
line = Line()
```
4. 添加数据
```
line.add_xaxis(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
line.add_yaxis("Series A", [11, 11, 15, 13, 12, 13, 10])
line.add_yaxis("Series B", [1, -2, 2, 5, 3, 2, 0])
```
5. 设置全局配置项
```
line.set_global_opts(title_opts=opts.TitleOpts(title="折线图示例"))
```
6. 渲染图表
```
line.render("line.html")
```
完整代码示例:
```
from pyecharts.charts import Line
from pyecharts import options as opts
line = Line()
line.add_xaxis(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
line.add_yaxis("Series A", [11, 11, 15, 13, 12, 13, 10])
line.add_yaxis("Series B", [1, -2, 2, 5, 3, 2, 0])
line.set_global_opts(title_opts=opts.TitleOpts(title="折线图示例"))
line.render("line.html")
```
运行代码后,会生成一个名为"line.html"的文件,打开即可看到折线图。
阅读全文
相关推荐














