我不知道如何更改类别轴的标记文本。我想提取这些文本,并插入另一个。所以,如果有人帮助我,我该如何处理这个案子,请!
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')
得到这个输出。雪落
在我的幻灯片中,只有一个条形图。有一个图表标题,"下雪"和四个类别轴标签。我想要得到这些类别轴标签。我希望有人能帮助我
你可以"get"(阅读)像这样的类别标签:
for category in chart.plots[0].categories:
print(category.label)
要更改它们,您需要重写图表的ChartData
,因为这些名称实际上存储在提供图表数据的嵌入式Excel工作表中。这是用Chart.replace_data()
方法完成的。