pyecharts堆叠面积图
时间: 2023-11-24 15:05:57 浏览: 264
以下是使用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, 40, 50, 70, 90]
y_data3 = [220, 300, 250, 180, 170, 210, 230]
# 创建Line对象
line = Line()
# 添加数据
line.add_xaxis(xaxis_data=x_data)
line.add_yaxis(
series_name="A",
stack="stack1",
y_axis=y_data1,
label_opts=opts.LabelOpts(is_show=False),
)
line.add_yaxis(
series_name="B",
stack="stack1",
y_axis=y_data2,
label_opts=opts.LabelOpts(is_show=False),
)
line.add_yaxis(
series_name="C",
stack="stack1",
y_axis=y_data3,
label_opts=opts.LabelOpts(is_show=False),
)
# 配置全局参数
line.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")
```
运行上述代码后,将生成一个名为`stacked_area_chart.html`的HTML文件,其中包含了堆叠面积图的可视化结果。
阅读全文