Himanshu
Himanshu

Reputation: 81

How to reverse the order of value axis in clustered bar chart using python-pptx module?

cluster_bar_chart_data = CategoryChartData()

# Adding categories to chart
cluster_bar_chart_data.categories = df['period'].to_list()

# Adding series
cluster_bar_chart_data.add_series("A",(df["A"].squeeze()), number_format=None)
cluster_bar_chart_data.add_series("B",(df["B"].squeeze()), number_format=None)
cluster_bar_chart_data.add_series("C",(df["C"].squeeze()), number_format=None)

x, y, cx, cy = Inches(7), Inches(1.2), Inches(6), Inches(5.5)

cluster_bar_chart = slide.shapes.add_chart(XL_CHART_TYPE.BAR_CLUSTERED, x,y, cx, cy, cluster_bar_chart_data)

I am using the above code for creating a cluster bar chart with 3 series. Below is the output I am getting: enter image description here

Expected Output:enter image description here

Is there any way to reverse the order of values at value axis?

Upvotes: 0

Views: 622

Answers (1)

scanny
scanny

Reputation: 28923

chart.category_axis.reverse_order = True

Should do the trick. You can read more about that property of an axis in the API documentation here:
https://python-pptx.readthedocs.io/en/latest/api/chart.html#pptx.chart.axis._BaseAxis.reverse_order

Upvotes: 1

Related Questions