我正在使用名为andplotly
的python 库。Ubuntu 18.04
Python 3.6
我需要将图形导出为.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]
请注意,我安装了orca
using: pip3 install orca
。我还在代码中添加了这一行:
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
但这并没有导致生成eps
文件。