无法在 Ubuntu 的 Python 的 Plotyl 中生成 eps 或 pdf 图表

Cannot produce an eps or pdf chart in Python's Plotyl in Ubuntu

我在 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 文件。

您没有正确安装 Orca。不幸的是你 cannot install Orca with pip. Instead follow Orca's installation method 4: standalone binaries:

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