python使用echarts绘制多折线图代码
时间: 2024-10-24 22:03:38 浏览: 46
要使用Echarts在Python中绘制多折线图,首先需要安装`pyecharts`库。下面是一个简单的示例代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Line
# 假设你有如下数据
data = {
"category": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
"line1": [120, 132, 101, 134, 90, 230, 210],
"line2": [220, 182, 191, 234, 290, 330, 310],
}
# 创建Line图表
chart = (
Line()
.add_xaxis(data["category"])
.add_yaxis("line1", data["line1"], linestyle_opts=opts.LineStyleOpts(width=2))
.add_yaxis("line2", data["line2"], linestyle_opts=opts.LineStyleOpts(width=2))
.set_global_opts(title_opts=opts.TitleOpts(title="多折线图"))
)
# 绘制并保存为HTML文件
chart.render("multi_line.html")
```
这段代码定义了一个包含两个系列("line1"和"line2")的折线图,每个系列的数据存储在一个字典中。`render()`函数用于生成一个HTML文件,这样其他人就可以通过浏览器查看这个动态图了。
阅读全文
相关推荐


















