python pptx XyChart setting label font size
<p>Within an python-pptx-generated XYchart, I would like to add labels to each point of the series. Code looks like this:</p>

<pre><code>for p, v in zip(chart.series[0].points, dataSeries):
    p.data_label.position = XL_LABEL_POSITION.ABOVE
    p.data_label.text_frame.clear()
    for paras in p.data_label.text_frame.paragraphs:
        paras.font.size = Pt(10)
    p.data_label.text_frame.text = str.format('{0:.1f}', v)
</code></pre>

<p>The new text is set correctly, but iterating through the paras to change font size has no effect. Any ideas how I could achieve a font size change for the labels?</p>

<p>You need to set the font size <em>after</em> adding the text frame text.</p>

<pre><code>data_label = p.data_label
...
text_frame = data_label.text_frame
# text_frame.clear()  # this line is not needed, assigning to .text does this
text_frame.text = str.format('{0:.1f}', v)
for paragraph in text_frame.paragraphs:
    paragraph.font.size = Pt(10)

# -- OR --

for run in text_frame.paragraphs[0].runs:
    run.font.size = Pt(10)
</code></pre>

<p>When you call <code>TextFrame.text</code>, all existing paragraphs are removed and a single new paragraph is added. Along the way, all character formatting is removed to produce a "clean slate" before adding the specified text.</p>

<p>I don't recall whether PowerPoint respects the font set at the paragraph level (using the <code>a:defRPr</code> element). If not, you'll need to do it at the run level, as shown after the -- OR -- line.</p>

python fonts size labels python-pptx