✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Convert plotly chart to pdf

Hello,

I am trying to convert plotly chart to pdf in google colab, but it runs error.
Could you please help?

Here is the code:

import plotly.graph_objects as go
import os

#%%

fig = go.Figure(go.Bar(

            x=[5, 16, 18],

            y=['Others', 'NO', 'YES'],

            orientation='h',

            text = [5, 16, 18],

            textposition='outside',

            width = 0.45           

   ))

#%%

fig.show()

#%%

if not os.path.exists("images"):

    os.mkdir("images")

#%%

fig.write_image("images/fig1.pdf")

Bests,
Ditsuhi

Hi @Ditsuhi welcome to the forum! A solution is given in https://stackoverflow.com/questions/57262385/saving-or-downloading-plotly-iplot-images-on-google-colaboratory/57272111#57272111

Yeah, it works. Thank you so much.

1 Like