在 PyCharm IDE 中嵌入 Plotly HTML

Embed Plotly HTML in PyCharm IDE

提问人:Sterling Butters 提问时间:9/12/2016 最后编辑:Sterling Butters 更新时间:7/9/2021 访问量:9367

问:

我想在PyCharm IDE中看到Plotly的HTML输出。它目前说:

进程已完成,退出代码为 0

用于输出。但是,我在 Jupyter 中收到图形结果

python html pycharm jupyter plotly

评论


答:

11赞 Kristian Vybiral 9/20/2016 #1

要查看 Plotly html 输出,请使用离线功能。例如,像这样:

plotly.offline.plot(*yourplotname*, filename='file.html')

在 pycharm 中运行代码,它会将 .html 文件本地保存在您的工作文件夹中,并在浏览器中打开 .html 进行查看。

评论

6赞 Dnaiel 8/31/2017
@kristian有没有办法将其制作为弹出窗口,而不必将其保存到文件中?
3赞 Minsky 8/31/2017 #2

Dnaiel,据我了解,它总是在某处创建一个 HTML 文件。即使在 jupyter 笔记本中,我假设 plotly 会创建一个临时 HTML 文件,尽管它在同一窗口中绘制图形。

但是,您仍然可以在 pycharm 中使用 plotly,而无需指定新文件的名称。在这种情况下,plotly 只需覆盖工作目录中以前的临时 HTML 文件。

plotly.offline.plot(df2.iplot(kind='TypeOfChart',x='X_Var',y='Y_Var', asFigure=True))  
1赞 Leej-1703 7/9/2021 #3

在 PyCharm 2020.3 中,我能够使用 poliastro 包制作多元素 3D 绘图。该图自动加载到具有交互功能的 Safari 中。

#%% Plotting in 3D
frame = OrbitPlotter3D(plane=Planes.EARTH_ECLIPTIC)
frame.set_attractor(Sun)

apollo_orbit = Orbit.from_ephem(Sun, apollo_ephem, EPOCH)
apollo_orbit.plot(label="Apollo", use_3d=True, interactive=True)

# frame.set_orbit_frame(Orbit.from_ephem(Earth, apollo_ephem_e, EPOCH))
# 2021-Jul-08 12:07 : First time trying plotly.offline.plot

fp = frame.plot(apollo_orbit)
frame.plot_body_orbit(Earth, EPOCH) # 2021-Jul-08 12:07 : Apparently adds to the object created in the previous line
plotly.offline.plot(fp)             # 2021-Jul-08 12:07 : Result is an html file that pops up in a browser, has interactive