gpt4 book ai didi

python-3.x - python-pptx 颜色图例未显示与图形相同的颜色

转载 作者:行者123 更新时间:2023-12-04 16:04:13 25 4
gpt4 key购买 nike

这让我抓狂。

    chart_AllData = slideref.shapes.add_chart(XL_CHART_TYPE.BAR_STACKED_100, x, y, cx, cy, chart_data)

chart = chart_AllData.chart
plot = chart.plots[0]
pointCount = 0
for answer in consolidatedAnswersList: # Looping over the answer codes
print('answer: ', answer)
catBar = plot.series[pointCount].points
for cat in catBar: # Looping over the categories (= the declarations)
fill = cat.format.fill
fill.solid()
colorString = ccpStatistics.gAnswerCodeColorDict.get(answer, 'FFFFFF')
r = int(colorString[0]+colorString[1], 16)
g = int(colorString[2]+colorString[3], 16)
b = int(colorString[4]+colorString[5], 16)
fill.fore_color.rgb = RGBColor(r , g , b)
print('setting ', answer, ' to ', colorString)
pointCount += 1

print(ccpStatistics.gAnswerCodeColorDict)

category_axis = chart.category_axis
category_axis.minor_tick_mark = XL_TICK_MARK.OUTSIDE
category_axis.tick_labels.font.italic = True
category_axis.tick_labels.font.size = Pt(12)

value_axis = chart.value_axis
value_axis.format.line.color.rgb = RGBColor(0 , 0 , 0)
value_axis.tick_labels.font.size = Pt(int(thisPageDict.get('SCALEFONTSIZE', ['18'])[0]))
value_axis.major_tick_mark = XL_TICK_MARK.OUTSIDE
value_axis.has_major_gridlines = True
value_axis.tick_labels.font.color.rgb = RGBColor(0,0,0)
value_axis.major_tick_mark.number_format = '0.0"%"'

chart.has_legend = True
chart.legend.position = XL_LEGEND_POSITION.RIGHT
chart.legend.include_in_layout = False # set to true
chart.legend.font.color.rgb = RGBColor(0,0,0)
chart.legend.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['12'])[0]))

plot.has_data_labels = True
data_labels = plot.data_labels

data_labels.position = XL_LABEL_POSITION.CENTER
data_labels.font.size = Pt(int(thisPageDict.get('LEGENDSIZE', ['10'])[0]))
data_labels.font.color.rgb = RGBColor(0x00, 0x00, 0x00)

ccpStatistics.gAnswerCodeColorDict的内容如下:

{'oaq_NoAnswer': 'DCDCDC', 'maq_NoAnswer': 'DCDCDC', 'Answer code': 'Answer code color', '1': 'FF0000', '2': 'FF6600', '3': 'FFC301', '4': '00B050', 'OK': '00B050', 'NOK': 'FF0000', 'NA': '333333', 'NEU': 'FF00FF', 'maq': '3A87AD', 'dq': '660000', 'txta': '660000', 'nq': '660000'}

现在,图表根据系列中的设置正确着色......图例中的系列名称也可以......但图例的颜色与条形图的颜色不对应。

注意,类似的代码似乎在其他方法中也能正常工作。我现在无计可施了。

See the resulting ppt chart

最佳答案

尝试在系列级别而不是在单个点级别设置颜色。

fill = series.format.fill
fill.solid()
fill.fore_color.rgb = RGBColor(r, g, b)

关于python-3.x - python-pptx 颜色图例未显示与图形相同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49403160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com