3

I intend to create the following chart using Python PPTX.enter image description here

Below code achieve the color setting, font size and number format. However, I am not yet able to rotate the data label, as I believe this API is not yet available in 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"]

To get started, I have created two minimal slides before and after rotating, and use opc-diag tool to find the diff.

<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

I believe I need to add rot="-5400000" XML element to lbl (plot.data_labels), but not clear on how to achieve this. I have used dir(), ._element and .xml on the chart and its children but not able to find <a:bodyPr> tag.

idazuwaika
  • 2,749
  • 7
  • 38
  • 46

1 Answers1

2

I tried below and it works.

if config["DATA_LABEL_VERTICAL"]:
    txPr = lbl._element.get_or_add_txPr()
    txPr.bodyPr.set('rot','-5400000')
idazuwaika
  • 2,749
  • 7
  • 38
  • 46
  • Well done idazuwaika! I would use `txPr` as the variable name rather than `r`, just to stay consistent with the convention used in `python-pptx`, but this gets the job done wonderfully :) – scanny Jun 14 '17 at 17:06
  • thanks. finally could do understand *very* little bit on the workaround function.. yea, I'm changing the variable name to stay with convention – idazuwaika Jun 16 '17 at 03:16