pyecharts堆积图
时间: 2023-12-08 10:02:49 浏览: 79
以下是使用pyecharts生成堆积面积图的示例代码和效果图:
```python
from pyecharts import options as opts
from pyecharts.charts import Line
# 准备数据
x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat",Sun"]
y_data1 = [120, 200, 150, 80, 70, 110, 130]
y_data2 = [60, 80, 70, 30, 40, 60, 70]
y_data3 = [220, 300, 250, 180, 170, 210, 230]
# 创建堆积面积图
line = (
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(series_name="A", y_axis=y_data1, stack="stack1")
.add_yaxis(series_name="B", y_axis=y_data2, stack="stack1")
.add_yaxis(series_name="C", y_axis=y_data3, stack="stack1")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="堆积面积图示例"),
tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
yaxis_opts=opts.AxisOpts(type_="value"),
)
)
# 渲染图表并保存到本地
line.render("stacked_area_chart.html")
```
效果图如下:
![堆积面积图示例](https://cdn.jsdelivr.net/gh/linlinjava/large-file-hosting/images/stacked_area_chart.png)
阅读全文