Trouble exporting figures from plotly using orca

  • Python
  • Thread starter Eclair_de_XII
  • Start date
In summary, exporting figures from plotly using orca can be problematic, as it requires a specific path for the orca executable and may not work on all operating systems. Additionally, there have been reported issues with exporting large or complex figures. These problems can be addressed by using alternative methods, such as the plotly image export API or using other packages like matplotlib or seaborn.
  • #1
Eclair_de_XII
1,083
91
TL;DR Summary
I have a bunch of figures created, and I wish to save them all into one folder in order to save myself the trouble of showing the figures on my browser, and then downloading each and every one of them.

To this end, I am following the instructions described here on how to do so:

https://plotly.com/python/static-image-export/

I am not skilled in programming, so I do not know why my command lines do not perform the intended function and return, instead, the error messages to be found below.
Python:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
    x=[0,0,1,1,0],
    y=[0,1,1,0,0],
    text=["Origin","$e_2$","","$e_1$"],
    textposition=["bottom left","top left","top center","bottom right"],
    mode='text+lines+markers'
))

orca="C:/Users/Eclair/.plotly/.orca"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/"

pio.orca.config.executable=orca
pio.orca.config.save()

arabella.write_image(direc,"arabella.png")

I executed this code, and the following error message was returned to me:

Code:
C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py
Traceback (most recent call last):
  File "C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py", line 20, in <module>
    arabella.write_image(direc,"arabella.png")
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\basedatatypes.py", line 2824, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1766, in write_image
    img_data = to_image(
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1532, in to_image
    ensure_server()
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1390, in ensure_server
    validate_executable()
  File "C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\io\_orca.py", line 1144, in validate_executable
    p = subprocess.Popen(
  File "C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

Process finished with exit code 1

If it matters, I am using the PyCharm interpreter. I did a bunch of searches on this issue, using the words on the last line as my search criteria. The answers ranged from what I presume to be bad directories, the interpreter's inability to find the executable orca file, and some other stuff that I am too code-illiterate to understand. I tried doing the thing requested by the error message and using the plotly.io.config.executable attribute in order to set the directory for the orca executable, which I assumed was the file referred to in this code:

Python:
import plotly.io as pio

print(pio.orca.config)

Code:
C:\Users\Eclair\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Eclair/.PyCharmCE2019.3/config/scratches/scratch_1.py
orca configuration
------------------
    server_url: None
    executable: C:/Users/Eclair/.plotly/.orca
    port: None
    timeout: None
    default_width: None
    default_height: None
    default_scale: 1
    default_format: png
    mathjax: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js
    topojson: None
    mapbox_access_token: None
    use_xvfb: auto

constants
---------
    plotlyjs: C:\Users\Eclair\AppData\Roaming\Python\Python38\site-packages\plotly\package_data\plotly.min.js
    config_file: C:\Users\Eclair\.plotly\.orca
 
Technology news on Phys.org
  • #2
You are likely missing some dependency like a window executable program that Is called by orca to do some work.

in your configuration the executable attribute doesn’t look like a valid windows executable name usually it would be something like C:\xxx\xxx.exe

so I would search around for that too as it may be the source of the error.

also maybe instead of the directory of the executable you provide the full path to the orca executable
 
  • #3
In this example, the executable line is simply orca

https://plotly.com/python/orca-management/

anyway you might find more stuff there as well

the article also mentions that plotless will search for the orca executable along the path so the path must have directory that contains the orca executable.
 
  • #4
I finally managed to find the orca.exe file; it turns out I had had it installed for almost two weeks, but did not know where it was. In any case, though, I've tried to link to the executable directly by making the correction to the code I posted in the opening post.

Code:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
    x=[0,0,1,1,0],
    y=[0,1,1,0,0],
    text=["Origin","$e_2$","","$e_1$"],
    textposition=["bottom left","top left","top center","bottom right"],
    mode='text+lines+markers'
))

orca="C:/Users/Eclair/AppData/Local/Programs/orca/orca"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/"

pio.orca.config.executable=orca
pio.orca.config.save()

print(pio.orca.config)

arabella.write_image(direc,"arabella.png")

It still returns the same error message. I do not know why that is.
error.png
 
  • #5
try placing "C:/Users/Eclair/AppData/Local/Programs/orca" in your windows command environment path parameter

and change the line:

Python:
pio.orca.config.executable="orca"

or

Python:
pio.orca.config.executable="orca.exe"
 
  • #6
jedishrfu said:
try placing "C:/Users/Eclair/AppData/Local/Programs/orca" in your windows command environment path parameter

I do not understand. Are you referring to the parameter named in line 14? I did try to fix the problem by appending ".exe" to the end of the string in this parameter, but I am not sure if I did it correctly.

Python:
from plotly import graph_objects as go
import plotly.io as pio

arabella=go.Figure()

arabella.add_trace(go.Scatter(
    x=[0,0,1,1,0],
    y=[0,1,1,0,0],
    text=["Origin","$e_2$","","$e_1$"],
    textposition=["bottom left","top left","top center","bottom right"],
    mode='text+lines+markers'
))

orca="C:/Users/Eclair/AppData/Local/Programs/orca/orca.exe"
direc="C:/Users/Eclair/Documents/2 LaTeX/active/arabella"

pio.orca.config.executable=orca
pio.orca.config.save()

arabella.write_image(direc,".png")

It exports a plain file, and not a png file, as intended.

error.png
 
  • #7
Windows has a path parameter.

When you're in a command session and type path you get to see what its value is. Windows uses it to search for commands that you might type in.

The website I sent earlier mentions the same thing. It says python will use the path to locate the orca command so you need to add the orca command directory to the path.

To set it on Windows:

https://www.computerhope.com/issues/ch000549.htm
 
  • #8
I am not sure if I have done this correctly. Is it normal for plotly to export images as plain files with no extensions?
error.png
 
  • #9
so it didn't return the file arrabella.png like you specified?
 
  • #10
It returns a plain file with no extension. I am not sure if this is intended or not. I can still open it using Paint and it will appear as if it were an image file, though. I was hoping to use the exported images in a LaTeX document, but I can likely find a way to use it as is.
 
  • #11
Eclair_de_XII said:
Python:
direc="C:/Users/Eclair/Documents/2 LaTeX/active/arabella"
...
arabella.write_image(direc,".png")

It exports a plain file, and not a png file, as intended.
It exports a file named C:/Users/Eclair/Documents/2 LaTeX/active/arabella because the argument to write_image is the filename to write, not a directory. So try:
Python:
file_path="C:/Users/Eclair/Documents/2 LaTeX/active/arabella/my-file-name.png"
...
arabella.write_image(file_path)
 
Last edited:
  • Like
Likes Eclair_de_XII
  • #12
That works. Thank you for all your help. I apologize; I probably should have asked this question at a proper technical support forum instead of at this one.
 

What is Plotly?

Plotly is a web-based data visualization platform that allows users to create interactive charts, graphs, and maps. It offers a variety of tools and features for data analysis and presentation.

What is Orca?

Orca is a command-line tool for generating static images of Plotly charts. It is used to export figures from Plotly and save them as image files.

Why am I having trouble exporting figures from Plotly using Orca?

There could be several reasons for this. Some common issues include outdated or incompatible versions of Orca, incorrect installation or configuration, and insufficient system resources. It is recommended to check the documentation and troubleshooting guide for Orca to resolve any issues.

How can I export figures from Plotly using Orca?

To export a figure from Plotly using Orca, you can use the "download" button on the chart or use the "plotly.io.write_image" function in the Plotly Python library. You will need to have Orca installed and configured properly for this to work.

Are there any alternatives to using Orca for exporting figures from Plotly?

Yes, there are a few alternatives to using Orca for exporting figures from Plotly. These include using the "plotly.offline.plot" function, which allows you to save a standalone HTML file of your chart, or using the "plotly.io.to_image" function, which uses an external service to generate static images of your chart.

Similar threads

  • Programming and Computer Science
Replies
8
Views
879
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
2
Views
320
  • Programming and Computer Science
Replies
9
Views
8K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
3
Views
895
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top