pythongoogle-colaboratoryplotly-pythonorca

How can I do a Static Image Export on Google Colab


I'm trying to export an image I've created with plotly as a .svg file.

This is the code I'm running to export it:

fig.write_image("/content/fig1.svg")

This is the error I'm getting:

Error - part 1

Error - part 2

I've entered in the github page of Orca and tried to use the installation codes they suggest but neither one worked.


Solution

  • You can install orca with the following code. (a library I wrote)

    !pip install kora -q
    import kora.install.orca
    

    Then it can write_image

    import plotly.graph_objects as go
    fig = go.Figure( go.Scatter(x=[1,2,3], y=[1,3,2] ) )
    fig.write_image("image.png")
    from IPython.display import Image
    Image("image.png")
    

    If you prefer to install orca yourself

    import os
    from urllib.request import urlretrieve
    url = "https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage"
    orca = '/usr/local/bin/orca'
    urlretrieve(url, orca)
    os.chmod(orca, 0o755)
    os.system("apt install xvfb libgconf-2-4")