Plotly 图表不显示在 PyCharm 中 [英] Plotly chart is not displayed in PyCharm

查看:144
本文介绍了Plotly 图表不显示在 PyCharm 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Pycharm 中显示交互式绘图?我运行以下代码:

How can I display interactive plotly graphs in Pycharm? I run the following code:

import plotly.offline as py
import plotly.graph_objs as go

py.init_notebook_mode(connected=True)

data = [go.Bar(
    x=['giraffes', 'orangutans', 'monkeys'],
    y=[20, 14, 23]
)]

py.iplot(data, filename="barplot")

PyCharm 中的结果是一个空白字段:

The result in PyCharm is a blank field:

在 Jupyter Notebook 中,此代码会给出一个(正确的)交互式图表作为结果.

In Jupyter Notebook this code gives a (proper) interactive chart as the result.

更新:在 PyCharm IDE 中嵌入 Plotly HTML 的答案对我不起作用.当我使用 plot() 函数(而不是 iplot())时,它会将图表导出到单独的文件中并在新窗口中打开浏览器.notebook 中的输出是生成图表的文件名.我想将图表包含到笔记本中并以交互方式使用它,就像在 Jupyter Notebook 中一样.这些答案只是关于将图表导出到单独的 html 文件中.

Update: Answers from Embed Plotly HTML in PyCharm IDE don't work for me. When I use the plot() function (instead of the iplot()) it exports the chart into separate file and open a browser in a new window. The output in notebook is the filename of the generated chart. I want to include the chart into notebook and use it interactively, like in Jupyter Notebook. That answers are only about exporting the chart into separate html file.

推荐答案

jayBana 的回答是正确的,但是如果你想在 PyCharm 中继续使用 .py 脚本,你可以简单地将默认渲染器设置为 'browser' 以获得交互式绘图图:

jayBana's answer is correct, but if you want to keep using .py scripts in PyCharm, you can simply set default renderer to 'browser' to get interactive plotly graphs:

import plotly.io as pio
pio.renderers.default = "browser"

如此处所述:https://plot.ly/python/renderers/

这篇关于Plotly 图表不显示在 PyCharm 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆