I have created a map with an overlay of markers and labels using plotly's scattermapbox utility in python. When I try to save the image as a .png file, the resolution of the map is terrible no matter what I set scale
to in the fig.write_image()
logic. Below is a code sample and the output image. You can see how the labels are distorted enough where I cannot read them. How can I save a higher resolution (i.e., less fuzzy) map?
Code snippet you can run after inputting a mapbox token:
import plotly.graph_objects as go
import pandas as pd
mapboxtoken = **PLACE YOUR MAPBOX TOKEN HERE**
data = pd.DataFrame.from_dict(
{
"latitude": {
0: 41.61848543654998,
1: 41.60974217360418,
2: 41.606083341611374,
3: 41.61506423238307,
4: 41.61777932615252,
},
"longitude": {
0: -76.55182449910664,
1: -76.54734344553233,
2: -76.56747692210295,
3: -76.56001621241725,
4: -76.56078604424849,
},
"well_name": {
0: "MCCONNELL - 2H",
1: "MCCONNELL - 5H",
2: "DRISCOLL - 2H",
3: "ROCKS - 5H",
4: "ROCKS - 2H",
},
}
)
fig = go.Figure()
fig.add_trace(
go.Scattermapbox(
lat=data.latitude,
lon=data.longitude,
name="Nearest Neighbors",
mode="markers+text",
text=data.well_name,
marker=go.scattermapbox.Marker(
size=8, color="rgb(108, 115, 110)", opacity=1
),
textposition="bottom center",
textfont=dict(family="sans serif", size=5, color="crimson"),
hoverinfo="text",
)
)
mean_lat = data["latitude"].mean()
mean_lon = data["longitude"].mean()
fig.update_layout(
autosize=True,
hovermode="closest",
margin=go.layout.Margin(
l=0, # left margin
r=0, # right margin
b=0, # bottom margin
t=0, # top margin
),
mapbox=dict(
accesstoken=mapboxtoken,
zoom=13.5,
center=dict(lat=mean_lat, lon=mean_lon),
),
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
showlegend=True,
)
fig.write_image("AFE_map.png", scale=6)
My output image is the following. Clearly, it is fuzzy. I even tried bumping scale up to 15, no luck.