Reputation: 53663
I just started using python-pptx, but have somewhat extensive experience working with Powerpoint between win32com, Visual Basic, Interop, etc., and I am seeing something funny when creating a chart with a single series.
Problem: a chart with a single series, by default, appears to be varying color fill per point/category. This is in contrast to what I'd expect: all points within a series should have the same color. (e.g., with win32com, these charts would have a single, consistent color across all points, buuuut there's some very finnicky stuff with win32com that requires basically rebuilding the ChartData and overwriting the default, plus the whole Application
instance is doing its thing behind the scenes, which we don't have in OpenXML or pptx, etc, so that might be a factor in this apparent discrepancy)
Question: Is this the normal/expected behavior for a chart with a single series? Or am I overlooking something obvious?
I saw a similar question and I was able to adapt your comments there to format the series consistently (below), but mainly I am wondering if this is necessary, or if I'm doing something wrong:
def FormatChart(chart):
plot = chart.plots[0]
plot.has_data_labels = True
dl = plot.data_labels
dl.position = XL_LABEL_POSITION.OUTSIDE_END
value_axis = chart.value_axis
value_axis.has_major_gridlines = False
s = plot.series[0]
s.format.fill.solid()
s.format.fill.fore_color.theme_color = MSO_THEME_COLOR_INDEX.ACCENT_1
Upvotes: 1
Views: 963
Reputation: 29021
This is the expected behavior. The easy way to change it is by setting the _BasePlot.vary_by_categories
property to False
:
plot = chart.plots[0]
plot.vary_by_categories = False
Upvotes: 2