I'm using Python pptx version 0.6.21
I'm trying to change a bar chart color according to its index Here's the code that I'm using:
for i in range(len(chart.series)):
point = chart.plots[0].series[i]
fill = point.format.fill
fill.solid
color = str(wrk_df.iloc[i, 4]).split(', ')
color = [int(i) for i in color]
print(color)
fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])
This one doesn't change the barchart color, but doesn't raise any exceptions. I've searched on Stack Overflow and found that you need to format data point and not the series. I used the code like this:
for i in range(len(chart.series)):
point = chart.series.points[i]
fill = point.format.fill
fill.solid
color = str(wrk_df.iloc[i, 4]).split(', ')
color = [int(i) for i in color]
print(color)
fill.fore_color.rgb = RGBColor(color[0], color[1], color[2])
This part raises an AttributeError:
AttributeError: 'SeriesCollection' object has no attribute 'points'
I've read that you need to upgrade python-pptx to the latest version, but I believe I'm already using the latest version possible.