简体   繁体   English

在 PyCharm IDE 中嵌入 Plotly HTML

[英]Embed Plotly HTML in PyCharm IDE

I would like to see Plotly's HTML output in the PyCharm IDE.我想在 PyCharm IDE 中看到 Plotly 的 HTML 输出。 It currently says:目前它说:

Process finished with exit code 0进程以退出代码 0 结束

for the output.为输出。 However, I receive a graphical result in Jupyter但是,我在 Jupyter 中收到了图形结果

To see the Plotly html output use the offline feature.要查看 Plotly html 输出,请使用离线功能。 For example, like this:例如,像这样:

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

Run the code in pycharm and it will save the .html file locally in your work folder and open the .html in your browser to view.在 pycharm 中运行代码,它会将 .html 文件本地保存在您的工作文件夹中,并在浏览器中打开 .html 进行查看。

Dnaiel, as far as I understand plotly, it always creates an HTML file somewhere. Dnaiel,据我所知,它总是在某处创建一个 HTML 文件。 Even in jupyter notebooks, I assume plotly creates a temporary HTML file although it draws the graph in the same window.即使在 jupyter notebooks 中,我也假设 plotly 创建一个临时 HTML 文件,尽管它在同一窗口中绘制图形。

However, you can still use plotly in pycharm without having to specify the name of the new file.但是,您仍然可以在 pycharm 中使用 plotly,而无需指定新文件的名称。 In that case, plotly simply overwrites the previous temporary HTML file in your working directory.在这种情况下,plotly 只是简单地覆盖工作目录中先前的临时 HTML 文件。

plotly.offline.plot(df2.iplot(kind='TypeOfChart',x='X_Var',y='Y_Var', asFigure=True))  

In PyCharm 2020.3, I was able to make a multi-element 3D plot, working with the poliastro package.在 PyCharm 2020.3 中,我能够使用 poliastro 包制作多元素 3D 绘图。 The plot auto-loaded into Safari with interactive features.绘图自动加载到具有交互功能的 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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