使用 IPython 未显示绘图图

发布于 2025-01-18 09:07:42 字数 894 浏览 5 评论 0原文

我正在尝试通过将 官方示例 粘贴到 IPython< 中来尝试情节表达/代码> 控制台。

requirements.txt

ipython
plotly
pandas

运行以下内容

import plotly.express as px

if __name__ == "__main__":
    import IPython; IPython.embed(using=False)

粘贴此内容:

In [1]:     df = px.data.gapminder().query("country=='Canada'")
   ...:     fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
   ...:     fig.show()
   ...: 

In [2]: 

什么也没有发生。如果我只是将整个过程作为脚本运行而不使用 IPython,它就可以正常工作(打开一个浏览器页面)。然而在开发过程中我宁愿​​能够玩玩。

有什么想法为什么这不起作用吗?

(此问题也发布在他们的社区页面)

I'm trying out plotly express by pasting the official example in an IPython console.

requirements.txt

ipython
plotly
pandas

Run the below

import plotly.express as px

if __name__ == "__main__":
    import IPython; IPython.embed(using=False)

Paste this:

In [1]:     df = px.data.gapminder().query("country=='Canada'")
   ...:     fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
   ...:     fig.show()
   ...: 

In [2]: 

Nothing happens. It works fine (a browser page opens up) if I just run the whole thing as a script without IPython. However during development I would rather be able to play around.

Any ideas why this isn't working?

(Posted this question also on their community page)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蒗幽 2025-01-25 09:07:42

你检查过这里吗?
https://plotly.com/python/troubleshooting/

我遇到了类似的问题,如果我使用 conda 从名为 my_env 的虚拟环境启动 Jupyter Notebook:conda activate my_env,然后是 jupyter notebook,然后是 fig.show()不会显示任何内容。在他们的故障排除页面之后,我发现 fig.show('notebook') 将使用 IPython 显示该图。我希望该链接能帮助您找到问题!

Have you checked here?
https://plotly.com/python/troubleshooting/

I'm having a similar issue where if I launch Jupyter Notebook from a virtual environment called my_env with conda: conda activate my_env and then jupyter notebook, then fig.show() won't show anything. Following their troubleshooting page, I found that fig.show('notebook') will show the figure using IPython. I hope that link will help you find the problem!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文