简体   繁体   中英

How do I embed Plotly charts exported as HTML in Powerpoint?

I am aware of adding URL to PPT, but due to certain privacy issues that cannot be done. Is there any other way to import plotly charts to ppt? or any equivalent open source app that can be used?

Thank you in advance!

import plotly.express as px
import pandas as pd
import numpy as np
from pathlib import Path

df = pd.DataFrame({
        "time": pd.date_range("1-Jul-2021", periods=200, freq="1H"),
        "desired_light": np.random.choice(["ON", "OFF"], 200),
    })

# build a figure
fig = px.bar(df, x="time", color="desired_light", height=400, title="Restaurant bills")
# export fingure as a static file: https://plotly.com/python/static-image-export/
fname = Path.cwd().joinpath("SO.png")
fig.write_image(fname)

# create a powerpoint from an image: https://python-pptx.readthedocs.io/en/latest/user/quickstart.html
from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)

left = top = Inches(1)
pic = slide.shapes.add_picture(str(fname), left, top)


prs.save(Path.cwd().joinpath('SO.pptx'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM