代码之家  ›  专栏  ›  技术社区  ›  Thomas

我怎样才能在pycharm中看到有情节的图形?

  •  0
  • Thomas  · 技术社区  · 5 年前

    我看到以下渲染器可用:

    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']
    

    但我不知道如何让Pycharm在IDE中显示输出,就像使用Matplotlib绘制图形一样。

    如何做到这一点?


    编辑:

    这是我使用的代码,来自plotly的示例:

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

    这将在Pycharm调试器中运行时打开浏览器选项卡以显示图形。


    编辑2:

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

    Plotly chart is not displayed in PyCharm

    0 回复  |  直到 3 年前
        1
  •  1
  •   buddemat nerdWannabe    3 年前

    遵循以下步骤:

    • 右键单击并选择“ 在python控制台中运行文件 "
    • 之后,浏览器将以图形输出打开

    请参见下面的屏幕截图:

    enter image description here

    Pycharm

        2
  •  1
  •   jayBana    5 年前

    以下步骤适用于我在macOs Mojave上使用PyCharm 2019.2,使用PyCharm内部的iPython笔记本电脑。

    我相信这应该适用于其他操作系统,以及其他支持Jupyter笔记本的PyCharm最新版本。

    我在用 conda 用于软件包和环境管理,但这应该与其他工具一起使用,例如pip或pipenv(考虑到orca是独立安装的)

    以下是我的步骤:

    创建并激活conda环境:

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

    按照以下说明安装Plotly 4.0及其依赖项: plotly.py's GitHub README for Jupyter Notebook Support

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

    除此之外,我还发现“Plotly Orca”是这项工作所必需的:

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

    请注意,以上内容适用于PyCharm for中的“配置服务器”和“托管服务器” .ipynb 使用以下示例代码的文件扩展名:

    #%%
    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();
    

    enter image description here

    补充说明:

    • 我相信Plotly的plot rendering在PyCharm的科学模式下对“普通”Python文件的处理方式与Matplotlib或Seaborn的处理方式不同。
        3
  •  1
  •   nicolaskruchten    5 年前

    有计划地。py版本4,它应该像调用 fig.show() svg 渲染器

    enter image description here