Hi,
I’m trying to plot a choropleth map that has exactly the size of a country (Denmark). I do this by setting “lonaxis_range” and “lataxis_range” equal to the extent of the country. However, Plotly seems to cut off the top part of the map and leaves room at the bottom, not respecting the lataxis range. For 1 country this effect is small, but when plotting multiple countries together a noticeable part of the top is cut off and extra space is added at the bottom.
I tried using “fitbounds=locations”. This does improve things but results in other problems so I prefer not to use it (e.g. it adds margins outside the layer extent showing only the basemap background). This suggests that the issue has something to do with the projection_rotation, center.lon, center.lat attributes and possibly projection_scale attributes. I tried settings these manually but haven’t been able to figure out the right settings for this.
For example, setting projection.rotation.lat equal to center.lat fixes the latitude cut off issue but increases the longitude beyond the lonaxis_range.
Example code
import json
import plotly.graph_objects as go
from urllib.request import urlopen
with urlopen('https://raw.githubusercontent.com/leakyMirror/map-of-europe/master/GeoJSON/europe.geojson') as response:
countries = json.load(response)
layout = {
"geo": go.layout.Geo(
projection=go.layout.geo.Projection(type='mercator'),
lonaxis_range=[8.076003, 15.193085],
lataxis_range=[54.559969, 57.751658],
visible=True
),
}
fig = go.Figure(
go.Choropleth(
geojson=countries,
locations=["DK", "SE", "DE"],
z=[1, 2, 3],
featureidkey="properties.ISO2",
colorscale="viridis",
showscale=False),
layout=layout)
fig.show()
Help greatly appreciated!