
[英]How embed HTML file (exported from Plotly) to Jupiter Notebook?
[英]How do I embed Plotly charts exported as HTML in Powerpoint?
我知道将 URL 添加到 PPT,但由于某些隐私问题无法完成。 有没有其他方法可以将plotly图表导入ppt? 或任何可以使用的等效开源应用程序?
先感谢您!
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'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.