How do you set the font size of a Chart Title with Python PPTX?

≯℡__Kan透↙ 提交于 2020-01-04 09:07:59

问题


I add a chart with:

doughnutchart_data.add_series('YTD COMPLETION TO PLAN', (PerformancePercent, NotPerformedPercent))

This gives me a chart title with the text, but how do I change the font size? This:

ThisDoughnutChart.title.font.size = Pt(12)

Gives me this error: AttributeError: 'Chart' object has no attribute 'title'


回答1:


It seems that creating a chart title text_frame over writes the title applied from the add_series attribute. So I tried adding a new title. This worked for me:

 ThisDoughnutChart.chart_title.text_frame.text = 'YTD COMPLETION TO PLAN'
 ThisDoughnutChart.chart_title.text_frame.paragraphs[0].font.size = Pt(12)



回答2:


Version 0.6.11 another example

shape = slide.shapes
title_shape = shape.title
title_shape.text_frame.paragraphs[0].font.size=Pt(10)



回答3:


You can set the global font size of the chart with the following:

ThisDoughnutChart.font.size = Pt(10)


来源:https://stackoverflow.com/questions/45600820/how-do-you-set-the-font-size-of-a-chart-title-with-python-pptx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!