Choropleth latitude is slightly off

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!

If the issue is that the accuracy of the basemap and geojson polygons do not match, the outline will match if you introduce go.Choroplethmapmox().

fig = go.Figure(
    go.Choroplethmapbox(
        geojson=countries,
        locations=["DK", "SE", "DE"],
        z=[1, 2, 3],
        featureidkey="properties.ISO2",
        colorscale="viridis",
        showscale=False),
    layout=layout)

fig.update_layout(autosize=True,
                  height=600
                 )
fig.update_layout(mapbox_style="carto-positron",
                  mapbox_zoom=5, mapbox_center = {"lat": 55.5, "lon": 12.5})
fig.show()

Thanks for the reply! The problem is that I specify the latitude range to be 54.56 - 57.75, but the map that is rendered has a slightly lower lower and upper bound, probably 54.5-57.70. This results in the top part of the map to be cut off and the bottom part to show extra margin. For small areas/countries the effect is small, but for larger areas (e.g. whole of Europe) a significant part of the top of the map is not displayed and a lot of extra margin at the bottom shows up.