I am runing the following code with Python 3.9.7 and plotly 5.14.1, in a regular python file (not a notebook), in VSCode:
import plotly.graph_objects as go
import plotly.io as pio
print(pio.renderers)
# defining vertices
V = [0, 1, 2, 3]
# defining their coordinates
lat = [42.33, 42.3, 42.31, 42.35]
lon = [-71.1, -71, -71.01, -71.1]
# defining edges
E = [(1, 2), (1, 3), (3, 2), (0, 2), (0, 3)]
fig = go.Figure(go.Scattermapbox(mode="markers", lon=lon, lat=lat, marker={"size": 10}))
for u, v in E:
fig.add_trace(
go.Scattermapbox(mode="lines", lon=[lon[u], lon[v]], lat=[lat[u], lat[v]])
)
fig.update_layout(
mapbox={
"center": {"lon": sum(lon) / 4, "lat": sum(lat) / 4},
"style": "stamen-terrain",
"zoom": 12,
},
)
print("Showing figure")
fig.show(renderer="jpg")
print("Figure shown")
The output I get is the following:
Renderers configuration
-----------------------
Default renderer: 'browser'
Available renderers:
['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
'cocalc', 'databricks', 'json', 'png', 'jpeg', 'jpg', 'svg',
'pdf', 'browser', 'firefox', 'chrome', 'chromium', 'iframe',
'iframe_connected', 'sphinx_gallery', 'sphinx_gallery_png']
Showing figure
And the code never stops running, "Figure shown" is never printed. I have to kill the terminal to stop execution, Ctrl+C is not working.
I tried with other values for render
in fig.show
:
jpeg
,png
,svg
: none of these work, the same thing is happening.browser
: a new tab is opened in my browser with the expected figure. I would like the same figure, but in .jpg format (or jpeg, png, ...)vscode
: a json is printed in the console
What is wrong with my code / my usage of plotly's API? How to fix it?
Thank you for your help.