美文网首页
如何解决plotly生成png格式图形?

如何解决plotly生成png格式图形?

作者: 游海东 | 来源:发表于2019-11-25 16:26 被阅读0次

    1、错误描述

    F:\PyCharmWorkSpace\NKJ\venv\Scripts\python.exe F:/PyCharmWorkSpace/NKJ/venv/djangos/C.py
    Figure({
        'data': [{'type': 'bar', 'y': [24, 56, 78, 98, 12, 68, 83]}], 'layout': {'template': '...', 'title': {'text': '销量'}}
    })
    Traceback (most recent call last):
      File "F:/PyCharmWorkSpace/NKJ/venv/djangos/C.py", line 10, in <module>
        f.show(renderer='png', width=1200, height=600)
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\basedatatypes.py", line 2783, in show
        return pio.show(self, *args, **kwargs)
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\io\_renderers.py", line 376, in show
        bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\io\_renderers.py", line 282, in _build_mime_bundle
        renderer.activate()
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\io\_base_renderers.py", line 126, in activate
        ensure_server()
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\io\_orca.py", line 1389, in ensure_server
        validate_executable()
      File "F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\plotly\io\_orca.py", line 1076, in validate_executable
        raise ValueError(
    ValueError: 
    The orca executable is required to export figures as static images,
    but it could not be found on the system path.
    
    Searched for executable 'orca' on the following path:
        F:\PyCharmWorkSpace\NKJ\venv\Scripts
        F:\Python38\Scripts\
        F:\Python38\
        F:\Tomcat\WINDOWS.X64_180000_db_home\bin
        C:\Program Files (x86)\Common Files\Oracle\Java\javapath
        C:\Windows\system32
        C:\Windows
        C:\Windows\System32\Wbem
        C:\Windows\System32\WindowsPowerShell\v1.0\
        F:\Java\jdk1.8.0_231\bin
        F:\Java\jdk1.8.0_231\jre\bin
        E:\apache-maven-3.3.3\bin
        G:\Git\cmd
        C:\Program Files (x86)\GtkSharp\2.12\bin
        C:\Program Files\Microsoft VS Code\bin
        F:\Graphviz2.38\bin
        C:\Program Files\MySQL\MySQL Server 5.7\bin
        F:\PowerBI\powerbi\oracle\instantclient_12_1\vc11
        F:\PowerBI\powerbi\oracle\instantclient_12_1
        C:\ProgramData\chocolatey\bin
        E:\Yarn\bin\
        F:\curl\curl-7.63.0\\I386
        F:\nodejs\
        F:\nodejs\node_global
        G:\TortoiseSVN\bin
        G:\TortoiseGit\bin
        F:\spss\JRE\bin
        C:\Program Files\MySQL\MySQL Shell 8.0\bin\
        E:\Python\Scripts\
        E:\Python\
        D:\Program Files (x86)\Elm Platform\0.18\bin
        E:\Python\Python36\Scripts\
        E:\Python\Python36\
        C:\Program Files\Docker Toolbox
        C:\Program Files\Microsoft VS Code\bin
        F:\nodejs\node_global
        C:\Users\Administrator.USER-0GUONPPBHK\AppData\Local\Yarn\bin
        C:\Users\Administrator.USER-0GUONPPBHK\AppData\Roaming\npm
        F:\IntelliJ IDEA 2019.1.1\bin
        
        F:\PyCharm\PyCharm20190203\bin
        
        F:\PyCharmWorkSpace\NKJ\venv\lib\site-packages\numpy\.libs
    
    If you haven't installed orca yet, you can do so using conda as follows:
    
        $ conda install -c plotly plotly-orca
    
    Alternatively, see other installation methods in the orca project README at
    https://github.com/plotly/orca
    
    After installation is complete, no further configuration should be needed.
    
    If you have installed orca, then for some reason plotly.py was unable to
    locate it. In this case, set the `plotly.io.orca.config.executable`
    property to the full path of your orca executable. For example:
    
        >>> plotly.io.orca.config.executable = '/path/to/orca'
    
    After updating this executable property, try the export operation again.
    If it is successful then you may want to save this configuration so that it
    will be applied automatically in future sessions. You can do this as follows:
    
        >>> plotly.io.orca.config.save()
    
    If you're still having trouble, feel free to ask for help on the forums at
    https://community.plot.ly/c/api/python
    
    
    Process finished with exit code 1
    

    2、错误原因
    在使用plotly库生成图形,然后保存为png格式,出现报错

    import plotly.graph_objects as go
    import plotly.io as io
    
    a = io.renderers['png']
    a.width = 1000
    a.height = 700
    b = go.Figure(data=[go.Bar(y=[264,568,788,928,142,648,853])], layout_title='人数')
    print(b)
    b.show(renderer='png', width=1000, height=700)
    

    3、解决办法
    需要安装orca,并配置环境变量,注意导出png格式

    import plotly.graph_objects as go
    import plotly.io as io
    
    a = io.renderers['png']
    a.width = 1000
    a.height = 700
    b = go.Figure(data=[go.Bar(y=[264,568,788,928,142,648,853])], layout_title='人数')
    print(b)
    b.show(renderer='png', width=1000, height=700)
    io.write_image(f,'data.png')
    

    相关文章

      网友评论

          本文标题:如何解决plotly生成png格式图形?

          本文链接:https://www.haomeiwen.com/subject/itljwctx.html