Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a border to picture(plot) in a PPTX generated by python and matplotlib

enter image description hereI have a plot which is generated by matplotlib then I save it as .png and then I place it on a PPT file using the pptx module. I want to add the border of the pic in my PPT file can any one please help me for the code..??

from pptx.util import Inches
from pptx import Presentation

prs = Presentation('dashboard.pptx')
left = Inches(0.5)
top = Inches(1)
slide = prs.slides.add_slide(prs.slide_masters[0].slide_layouts[2])
pic = slide.shapes.add_picture('test.png',left, top,width =None ,height =None)
prs.save('dashboard_new.pptx')
like image 224
MoChen Avatar asked Oct 20 '22 03:10

MoChen


1 Answers

The Picture object in python-pptx has a line attribute that provides access to border properties:

  • http://python-pptx.readthedocs.org/en/latest/api/shapes.html#picture-objects
  • http://python-pptx.readthedocs.org/en/latest/api/dml.html#pptx.dml.line.LineFormat

So the code would go something like this:

from pptx.dml.color import RGBColor

line = pic.line
line.color.rgb = RGBColor(0xFF, 0x00, 0x00)
line.width = Inches(0.1)
like image 153
scanny Avatar answered Oct 22 '22 11:10

scanny