Python-pptx:更改堆积条形图的颜色

问题描述

我使用以下代码构建了一个堆积条形图,但我想更改每个类别的颜色。现在它们基于主题。如何更改颜色?

谢谢

stacked bar chart

chart_data = CategoryChartData()
    chart_data.categories = df.index
    for mapping in data.Mapping.unique():
        list_ = []
        for cl in df.index:
            try:
                list_.append(data[data.Mapping == mapping].groupby("cl").sum()["score"][cl])
            except:
                list_.append(0)
        chart_data.add_series(mapping,list_)

# add chart to slide --------------------
x,y,cx,cy = Inches(0.5),Inches(2),Inches(7),Inches(5)
graphic_frame = slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_STACKED,x,cy,chart_data)
chart = graphic_frame.chart

category_axis = chart.category_axis
category_axis.tick_labels.font.size = Pt(10)

value_axis = chart.value_axis
value_axis.has_minor_gridlines = False

tick_labels = value_axis.tick_labels
tick_labels.font.size = Pt(10)

chart.has_legend = True
legend = chart.legend
legend.include_in_layout = False
legend.font.size = Pt(10)
legend.position = XL_LEGEND_POSITION.CUSTOM

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)