我怎样才能在pycharm中看到绘图? [英] how can I see plotly graphs in pycharm?

查看:1439
本文介绍了我怎样才能在pycharm中看到绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到以下渲染器可用:

I see the following renderers are available:

Default renderer: 'browser'
    Available renderers:
        ['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
         'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
         'json', 'png', 'jpeg', 'jpg', 'svg', 'pdf', 'browser',
         'firefox', 'chrome', 'chromium', 'iframe', 'iframe_connected',
         'sphinx_gallery']

但是我看不到如何在IDE中让pycharm显示输出,就像我用matplotlib绘制图形时一样.

but I don't see how I can get pycharm to show the output, in the IDE, like when I do graphs with matplotlib.

这怎么办?

这是我使用的代码,可从以下示例获取:

this is the code I use, sample from plotly:

fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="test"
)
fig.show()

这将打开一个浏览器选项卡,以显示在pycharm调试器中运行时的图形.

this will open a browser tab to show the graph while run in the pycharm debugger.

Edit2:

一年前,我看到一个类似的问题,但没有解决方案:

I see a similar question, from a year ago, with no solution:

PyCharm中未显示剧情图

推荐答案

下面的步骤适用于在MacOs Mojave上使用PyCharm内部的iPython笔记本的PyCharm 2019.2.

The steps below work for me with PyCharm 2019.2 on macOs Mojave using iPython notebooks from within PyCharm.

我相信,这应该在其他操作系统以及支持Jupyter笔记本的PyCharm的其他最新版本中也可以使用.

I believe that this should work on other operating systems as well with other recent versions of PyCharm supporting Jupyter notebooks as well.

我正在使用conda进行程序包和环境管理,但这也应与其他工具配合使用,例如pip或pipenv(假设orca独立安装)

I am using conda for package and environment management but this should work with other tools as well e.g. pip or pipenv (given that orca is installed standalone)

这是我的步骤:

创建并激活conda环境:

Create and activate conda environment:

  • $ conda create -n pycharm-plotly python
  • $ conda activate pycharm-plotly
  • $ conda create -n pycharm-plotly python
  • $ conda activate pycharm-plotly

根据 plotly.py的GitHub README,安装Plotly 4.0及其依赖项Jupyter Notebook支持

  • $ conda install -c plotly plotly==4.0.0
  • $ conda install "notebook>=5.3" "ipywidgets>=7.5"
  • $ conda install -c plotly plotly==4.0.0
  • $ conda install "notebook>=5.3" "ipywidgets>=7.5"

此外,我发现需要"Plotly Orca"才能起作用:

In addition, I found that "Plotly Orca" is required for this to work:

  • $ conda install -c plotly plotly-orca psutil requests

请注意,对于使用以下示例代码的.ipynb文件扩展名,PyCharm中的"Configured Server"和"Managed Server"均适用:

Please note that the above works with both "Configured Server" and "Managed Server" from within PyCharm for .ipynb file extensions using the following sample code:

#%%
import plotly.graph_objects as go
import plotly.io as pio

pio.renderers.default = 'png'

fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"
)
fig.show();

附加说明:

  • 我相信PyCharm的科学"模式下的Plotly绘图绘制不能与普通" Python文件一起使用,就像Matplotlib或Seaborn一样.

这篇关于我怎样才能在pycharm中看到绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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