在python和matplotlib生成的PPTX中为图片(图表)添加边框

《在python和matplotlib生成的PPTX中为图片(图表)添加边框》I有一个由matplotlib生成的图,然后我将其保存为.png,然后使用pptx模块将其放在PPT文件中.

我想在我的PPT文件中添加图片的边框可以任何一个请帮我代码.. ??

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')

最佳答案 python-pptx中的Picture对象有一个line属性,可以访问border属性:

> 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

所以代码会是这样的:

from pptx.dml.color import RGBColor

line = pic.line
line.color.rgb = RGBColor(0xFF, 0x00, 0x00)
line.width = Inches(0.1)
点赞