0

I am using pypptx & jupyter noteboook to automate presentations,

1st i imported the local png like this

import pyppt as ppt
from IPython.display import Image
Image(filename='op.png') # opening the image in jupyter notebook

but when i tried to display it in powerpoint using the below code, it is not being displayed in the ppt

ppt.add_figure('BottomLeft')

instead i am getting this outline of the image in the ppt,but not the image itself enter image description here

please also suggest better libraries for achieving this & for better ppt automation in general.

EDIT 1 - below is the code that i used to create the image & export.

import plotly.graph_objects as go
headerColor = 'skyblue'
rowEvenColor = '#017dbb'
rowOddColor = 'white'

fig = go.Figure(data=[go.Table(header=dict(values=pivot.columns,line_color='darkslategray',fill_color=headerColor,align=['left','center'],font=dict(color='white', size=12) ),
cells=dict(values=[pivot[i] for i in pivot.columns],line_color='darkslategray',fill_color = [['white','#007680','white', '#017dbb','white']*5],align = ['left', 'center'],font = dict(color = 'darkslategray', size = 11)
))])
fig.show()

fig.write_image("op.png") #export
  • I think you are confusing 'figure' concept. If you look at the [pyppt github repo](https://github.com/vfilimonov/pyppt) it makes it clear that a matplotlib 'figure object' is what 'figure' refers to in the 'add_figure()' method. What you've done is load in an image and expect that to be used. (I assume maybe your image file was produced from a previous use of matptlotlib, but I cannot tell that for sure from your post.) A matplotlib 'figure object' is a special object made by matplotlib running at the time; it's not an image. – Wayne Oct 01 '22 at 18:47
  • [python-pptx](https://python-pptx.readthedocs.io/en/latest/) is a Python package that has [an `add_picture()` method](https://python-pptx.readthedocs.io/en/latest/user/quickstart.html?highlight=add_picture#add-picture-example). See also [here](https://stackoverflow.com/a/44275563/8508004). That package should be able to handle automating addition of your '`op.png`' image file. – Wayne Oct 01 '22 at 18:52
  • @Wayne actually yes, i created that image in plotly, but that was an interactive image that i could not print to my ppt directly, so i exported it as a static image, the code is in edit 1 of the post. – Paras Chopra Oct 02 '22 at 08:16
  • Since that was an image file hopefully what I said helped you figure it out and your addition is working in powerpoint now? If not, here's the summary: You cannot use the '`add_figure()'` method from pyppt because you aren't working with matplotlib-generated figure objects. For the record, plotly is very different than matplotlib, but that point is moot here because you really have an image file you saved. You should be able to use python-pptx's '`add_picture()`' method to bring your image file into a slide. – Wayne Oct 02 '22 at 15:27
  • As an aside to your main point if trying to work with `op.png`, it looks like there is a package for working with Plotly and Powerpoint, see https://pypi.org/project/plotlyPowerpoint/ . It may allow you to do with Plotly plots what pyppt is meant to allow with matplotlib plots. – Wayne Oct 02 '22 at 15:30

0 Answers0