1
votes

I don't know how to change the tick label text of category axis. I want to extract these texts and insert with another. So, if someone help me how can I do with this case, please!

from pptx.enum.chart import XL_CHART_TYPE
from pptx import Presentation
proj1 = Presentation("C:/Users/naych/Documents/chart.pptx")
for slide in proj1.slides:
    for shape in slide.shapes:
        if shape.has_chart:
            chart=shape.chart
           
            if chart.chart_title.has_text_frame:
                print(chart.chart_title.text_frame.text)
                category_axis=chart.category_axis
                category_axis.tick_labels.font.italic=True
                           
proj1.save('new_chart_lang.pptx')

and I got this output. Snow falling

In my slide, there are only one bar chart. There are one chart title, 'Snow falling' and four category axis labels. I wanna to get these category axis labels. I hope someone can help me

1

1 Answers

1
votes

You can "get" (read) the category labels like this:

for category in chart.plots[0].categories:
    print(category.label)

To change them, you need to rewrite the ChartData for the chart, because these names are actually stored in the embedded Excel worksheet that provides the chart's data. That is accomplished using the Chart.replace_data() method.