You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python的xlsxwriter库是否支持创建Pie-of-Pie(复合饼图)?

Xlsxwriter支持Pie-of-Pie(复合饼图)功能

是的,xlsxwriter完全支持创建Excel的Pie-of-Pie复合饼图,只需在创建图表时指定对应子类型,并配置拆分规则即可。

核心修改点

把你现有代码的图表创建语句加上subtype: "pie_of_pie"参数,同时通过split选项定义切片拆分规则,按需添加子饼图的明细数据系列。

代码示例(适配你的场景)

假设你需要将主饼图中某一部门的总工时切片,拆分为下属小组的明细数据:

# 创建Pie-of-Pie复合饼图
chart4 = workbook.add_chart({'type': 'pie', 'subtype': 'pie_of_pie'})

# 添加主饼图系列:各部门总工时
chart4.add_series({
    "name": "Hours by Directorate",
    "categories": directoratePieAxis,  # 示例:['Sheet1', 'A2:A5'],部门名称范围
    "values": directoratePieSeries,    # 示例:['Sheet1', 'B2:B5'],部门总工时范围
    # 配置拆分规则:手动指定第3个切片(索引从0开始)拆分到子饼
    "split": {
        "type": "custom",
        "points": [2],  # 指定要拆分的切片索引
        "second_plot_size": 70,  # 子饼图大小为主饼的70%
        "gap_width": 20          # 主饼与子饼的间距
    }
})

# 添加子饼图系列:对应部门的下属小组工时明细
chart4.add_series({
    "categories": subGroupAxis,  # 示例:['Sheet2', 'A2:A4'],小组名称范围
    "values": subGroupSeries    # 示例:['Sheet2', 'B2:B4'],小组工时范围
})

# 可选:为子饼图添加数据标签
chart4.set_second_plot({
    'data_labels': {'percentage': True, 'category_name': True}
})

# 将图表插入目标工作表
worksheet.insert_chart('D2', chart4)

常用拆分规则说明

  • 按位置拆分:"split": {"type": "position", "value": 2} 将最后2个切片移到子饼
  • 按数值拆分:"split": {"type": "value", "value": 100} 将数值小于100的切片移到子饼
  • 按百分比拆分:"split": {"type": "percentage", "value": 10} 将占比小于10%的切片移到子饼
  • 自定义拆分:"split": {"type": "custom", "points": [0, 3]} 手动指定索引为0和3的切片移到子饼

内容的提问来源于stack exchange,提问作者doneal24

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 13:35:33