使用 IPython 未显示绘图图
我正在尝试通过将 官方示例 粘贴到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你检查过这里吗?
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 thenjupyter notebook
, thenfig.show()
won't show anything. Following their troubleshooting page, I found thatfig.show('notebook')
will show the figure using IPython. I hope that link will help you find the problem!