Python PPTX suppress zero values in a stacked Bar Chart
Is there a possibility to suppress zero values in a stacked bar chart like the following.
Manually, it's at least possible to remove the zero values in the Excel workbook while keeping the order (bad, medium, good). I tried to replace the zeros in the numpy array by NaN and then adding it by using add_series. As soon as I want to replace the data, I get the following error:
{TypeError} NAN/INF not supported in write_number() without 'nan_inf_to_errors' Workbook() option
My code snippet looks like:
chart_data = ChartData()
chart_data.categories = labels
chart = graphic_frame.chart
for index, row in df.iterrows():
values = row.values
values[values == 0] = np.nan
chart_data.add_series(index, (values))
chart.replace_data(chart_data)
Or is there an alternative going deeper in the xml code to hide specifically zero labels?
Link to stackoverflow: https://stackoverflow.com/questions/73853536/python-pptx-suppress-zero-values-in-a-stacked-bar-chart
The trick I found to work on my cases is to set the value to None in these situations. This could work to set the label to empty too depending on how the label is set up.
I am not sure if this will match perfectly your use case, but it is worth a test.
