复合柱状图用多个系列的柱面表示多组数据的大小。常用多种颜色或多种填充方式来表现这多个系列的柱面。
\[\]
根据给定数据绘图,编写pyECharts代码如下所示:
code.python
import pandas as pd
from pyecharts.charts import Bar
from pyecharts import options as opts
df=pd.read_excel('07 销售收入0.xlsx',engine='openpyxl',index_col=0)
categories = df.index.tolist() # 索引列作为横轴
# 1. 创建复合柱状图
bar = Bar()
bar.add_xaxis(categories)
# 2. 动态添加所有数据系列
for col in df.columns[0:]: # 从第1列开始
bar.add_yaxis(col, df[col].tolist())
# 3. 配置图表
bar.set_global_opts(
title_opts=opts.TitleOpts(title="复合柱状图"),
toolbox_opts=opts.ToolboxOpts())
bar.render("bar2.html")
运行代码,生成下图。
\[\]