I am using the python library called plotly
on Ubuntu 18.04
and Python 3.6
.
I need to export the graphs as .eps
or .pdf
files.
I use this sample code:
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")
But the figure is shown in a new tab in the browser. It is not written as eps
. Also, in the command line where I run the python file, I see:
/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]
Note that I installed the orca
using: pip3 install orca
. I also added this line in the code:
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
But this did not result in producing the eps
file.
You do not have Orca properly installed. Unfortunately you cannot install Orca with pip. Instead follow Orca's installation method 4: standalone binaries:
wget
from Orca's release page. At the time of writing it was: wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage