How can I convert density_mapbox to png image?

I have a project and I have to convert plotly map to png. But when I search and try it I saw that I can only convert it to html file.
I wonder if it is possible to convert plotly plot to png or jpg file?

You can use this as example.
Thanks in advance!!

import as px
fig = px.density_mapbox(lat=[37.2303], lon=[28.0908], radius=8,
                        center=dict(lat=37.2303, lon=28.0908), zoom=8,

(Note: I know that I can do this by click the ‘download plot as png’ button, but i should do this wiyh codes.)

See Static Image Export | Python | Plotly

Hahaa this is funny. I didnt expect this’ll be easy like this. Thank you soo much!!


Thanks for help, Looking for same issue and i found lots of information here, Really appreciate for help.

If you didnt realize that .write_image() method requires kaleido.

!pip install -U kaleido

If you deploy your app with docker.