在python-pptx中是否可以为条形图中的特定条涂上不同于其他颜色的条形?我的意图是根据值为条形着色。默认情况下,所有颜色均为蓝色,但是如果该值低于特定阈值,则该条将变为红色。
下面是我当前的代码,所有条形都呈蓝色,rgb(65,105,225)
# 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)
我还没有测试过,但是我相信它会起作用:
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的文档中有一个空白,这就是为什么您可能找不到这个空白的原因。
让我们知道你的状况:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句