【问题标题】:Cannot produce an eps or pdf chart in Python's Plotyl in Ubuntu无法在 Ubuntu 的 Python Plotly 中生成 eps 或 pdf 图表
【发布时间】:2019-09-10 13:51:03
【问题描述】:

我在Ubuntu 18.04Python 3.6 上使用名为plotly 的python 库。

我需要将图表导出为.eps.pdf 文件。

我使用这个示例代码:

    import plotly.graph_objects as go
    import decimal
    import plotly
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'

    x = ['Product A', 'Product B', 'Product C']
    y = [(20/80)*100, (14/80)*100, round(decimal.Decimal(2.256),2)]

    # Use textposition='auto' for direct text
    fig = go.Figure(data=[go.Bar(
                x=x, y=y,
                text=y,
                textposition='auto',
            )])

    fig.show()
    fig.write_image("fig1.eps")

但该图显示在浏览器的新选项卡中。它不写为eps。此外,在我运行 python 文件的命令行中,我看到:

/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py:84: UserWarning:

Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.

Traceback (most recent call last):
  File "sample.py", line 15, in <module>
    fig.write_image("fig1.eps")
  File "/usr/local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 2688, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1705, in write_image
    fig, format=format, scale=scale, width=width, height=height, validate=validate
  File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1482, in to_image
    ensure_server()
  File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1344, in ensure_server
    validate_executable()
  File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1139, in validate_executable
    raise ValueError(err_msg)
ValueError: 
The orca executable is required in order to export figures as static images,
but the executable that was found at '/usr/bin/orca'
does not seem to be a valid plotly orca executable. Please refer to the end of
this message for details on what went wrong.

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

Here is the error that was returned by the command
    $ /usr/bin/orca --help

[Return code: -11]

请注意,我使用 pip3 install orca 安装了 orca。我还在代码中添加了这一行:

plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'

但这并没有导致生成eps 文件。

【问题讨论】:

    标签: python python-3.x plotly orca plotly-python


    【解决方案1】:

    您没有正确安装 Orca。不幸的是你cannot install Orca with pip。而是按照Orca的安装方法4:standalone binaries

    1. Orca's release page 下载带有wget 的.AppImage。在撰写本文时是:wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage
    2. 关注Linux install instructions。确保您也确实遵循故障排除指南(两者) - 这并不容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 2015-06-19
      • 2016-04-27
      相关资源
      最近更新 更多