Plotly create inset choropleth (Mapbox ideally) of Alaska and Hawaii

Is there a way to create additional choropleth (ideally Mapbox choropleths, but I’d settle for Plotly’s standard choropleth function) maps and layer them on top of a base choropleth so that I can easily show data related to Alaska and Hawaii with the continental US?
Something like this

Don’t believe my existing code is necessarily helpful, but here’s how I build my base map (removed my custom style so that anyone should be able to generate).

fig = px.choropleth_mapbox(
    df_mar,
    geojson=puma,
    locations="stpuma",
    color="inter_pct",
    range_color=(0,25),
    color_continuous_scale="Viridis",
    labels={"inter_pct": "Marriage (%)"},
    center={"lat": 37.0902, "lon": -95.7129},
    zoom=4.2,
    opacity=1.0,
    mapbox_style="white-bg"
)
fig.update_layout(
    coloraxis_colorbar=dict(
        bgcolor="rgba(22,33,49,1)",
        title="Marriage,<br>Percent Share",
        titlefont=dict(
            color="rgba(255,255,255,1)"
        ),
        tickfont=dict(
            color="rgba(255,255,255,1)"
        ),
    ),
    margin=dict(
        l=50,
        r=50,
        b=50,
        t=50,
        pad=4
    ),
    paper_bgcolor = "rgba(8,18,23,1)",
    plot_bgcolor = "rgba(8,18,23,1)",
    showlegend = True,
    annotations = [
        dict(
            x=-0.025,
            y=-0.04,
            xref='paper',
            yref='paper',
            text='Source: Census ACS 5 2015-2019',
            showarrow = False,
            font=dict(
                color="rgba(255,255,255,1)"
            ),
            bgcolor="rgba(8,18,23,1)",
        )
    ]
)
fig.update_traces(
    marker_line_width=0,
    below="waterway"
)
fig.show(width=1920, height=1080)

@hillard28
I created a minimal working example of US map and an inset for Alaska. You have to add go.Choroplethmapbox for both US and Alaska, instead my go.Scattermapbox(es).

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(
    specs=[[{'type': 'mapbox'}]],
    insets=[{'type': 'mapbox',
             'l':0.0,
             'w':0.25,
             'h':0.48}])


fig.add_trace(go.Scattermapbox(lon=[-101.29], lat=[42.11], marker_size=8))  # 47.1164° N, 101.2996° W
fig.add_trace(go.Scattermapbox(lon=[-150.49], lat=[64.80], subplot= "mapbox2"))  #64.2008° N, 149.4937° W

fig.update_layout(mapbox=dict(style="open-street-map", center_lon=-101.29, center_lat=42.11, zoom=1.75 ),
                 mapbox2=dict(style="open-street-map", center_lon =-150.49, center_lat=64.80, zoom=1.55))

These are the keywords for inset definition ( i got them printing help(make_subplots)

insets: list of dict or None (default None):
        Inset specifications.  Insets are subplots that overlay grid subplots
    
        - Each item in 'insets' is a dictionary.
            The available keys are:
    
            * cell (tuple, default=(1,1)): (row, col) index of the
                subplot cell to overlay inset axes onto.
            * type (string, default 'xy'): Subplot type
            * l (float, default=0.0): padding left of inset
                  in fraction of cell width
            * w (float or 'to_end', default='to_end') inset width
                  in fraction of cell width ('to_end': to cell right edge)
            * b (float, default=0.0): padding bottom of inset
                  in fraction of cell height
            * h (float or 'to_end', default='to_end') inset height
                  in fraction of cell height ('to_end': to cell top edge)

For your examples you have to choose an adequate 'w' (width) and 'h' (height) for the inset, and zoom value for each mapbox.
Here is the image of the above fig of Scattermapboxes:

1 Like

Thanks for this! Seems to be exactly what I was looking for. Now I assume the answer is no because it could be applied to the main image, but is there anyway to remove the attribution from the inset? I obviously want to keep it for the main panel, but it’s a bit distracting to have two!

Edit: Actually, on a similar note; is it possible to move the attribution text? I’d like to have it on the paper, as opposed to the plot, but don’t see anything related to position.

@hillard28 The attribution is not added to all mapbox- styles and choroplets.
LE: Example of choropleth with layout.mapbox defined as follows:

mapbox=dict(style='carto-positron',
                              zoom=6.5, 
                              center = {"lat": 46.8181877 , "lon":8.2275124 })