Python 旋转图表数据标签的 PPTX 变通函数

Python PPTX workaround function for rotating chart data labels

我打算使用 Python PPTX 创建以下图表。

下面的代码实现了颜色设置、字体大小和数字格式。但是,我还不能旋转数据标签,因为我相信这个 API 在 python-pptx 0.6.5

中还不可用
lbl = plot.data_labels
lbl.font.size = config["DATA_LABEL_FONT_SIZE"]
lbl.font.color.rgb = config["DATA_LABEL_FONT_COLOR"]
lbl.number_format = config["DATA_LABEL_NUMBER_FORMAT"]
lbl.position = config["DATA_LABEL_POSITION"]

首先,我在旋转前后创建了两个最小幻灯片,并使用 opc-diag 工具找到差异。

<a:bodyPr rot="-5400000" spcFirstLastPara="1" vertOverflow="ellipsis"
vert="horz" wrap="square" lIns="38100" tIns="19050" rIns="38100" 
bIns="19050" anchor="ctr" anchorCtr="1">\n                 
<a:spAutoFit/>\n </a:bodyPr>\n

我认为我需要将 rot="-5400000" XML 元素添加到 lbl (plot.data_labels),但不清楚如何实现。我在图表及其子项上使用了 dir()._element.xml,但无法找到 <a:bodyPr> 标签。

我在下面尝试过并且有效。

if config["DATA_LABEL_VERTICAL"]:
    txPr = lbl._element.get_or_add_txPr()
    txPr.bodyPr.set('rot','-5400000')