Search code examples
pythonpandasplotly-express

Plotly express export to png inside for loop


I have a code where I am generating the pots using fig(show) inside a loop and this works fine. I would like to be able to export this into the different PNG files based on the for loop. I have tried different options like %s, but doesn't work;

my_dfs = {}
Name = ['A','B','C',]
for name in Name:

fig.write_image("C:\aa\pandas\VIP\%s.png" % name)

I would like to create A.png, B.png and C.png based on the loop.

Fig.show() shows me the images I need but I need to export to png


Solution

  • You should use raw string (prefixed with r)

    r"C:\aa\pandas\VIP\%s.png"
    

    In the normal string, python may replace sequence of backslash (\) and other characters with another character.