2017-02-11 89 views
1

python-pptx是否有可能在不同于其他条形图中的特定条形上色?我的意图是根据数值对栏进行着色。默认情况下,全部为蓝色,但如果该值低于某个阈值,则该栏会显示为红色。不同于Python的颜色特定条形图PPTX

下面是我用所有的酒吧当前代码蓝色十岁上下,RGB(65105225)

# HUMIDITY CHART 
    chart_data = ChartData()    
    chart_data.categories = list(m.columns) 

    chart_data.add_series('Humidity', list(m.loc[svc,'Humidity']), 3) 
    graphic_frame = s.placeholders[14].insert_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, chart_data) 
    chart = graphic_frame.chart 

    plot = chart.plots[0] 
    plot.has_data_labels = True 
    plot.overlap = 0 
    plot.gap_width = 30 
    data_labels = plot.data_labels 
    data_labels.font.size = Pt(11) 
    data_labels.font.color.rgb = RGBColor(0,0,0) 
    data_labels.number_format = "#,##0" 

    chart.series[0].fill.solid() 
    chart.series[0].fill.fore_color.rgb = RGBColor(65,105,225) 

回答

1

我没有测试过这一点,但我相信它会工作:

bar_idx = the_offset_of_the_bar_I_want_to_set_to_a_different_color 
point = series.points[bar_idx] # a (data) point in a bar chart is a bar 
fill = point.format.fill 
fill.solid() 
fill.fore_color.rgb = RGBColor(65, 105, 225) 

有在series.points的文档中存在缺口,这就是为什么你可能没有找到这个。

让我们知道你如何去:)

+0

谢谢,但我接受任何AttributeError的:“检测BarSeries”对象有没有属性“点”,或AttributeError错误:“的SeriesCollection”对象在我的各种没有属性“点”尝试。 – idazuwaika

+0

尝试了两个点= chart.series.points [bar_idx]和point = chart.series [0] .points [bar_idx] – idazuwaika

+0

您使用的是什么版本的'python-pptx'?听起来像是升级的时候了。 BarSeries应该有'.points'属性。 – scanny