Skip to content
Advertisement

Inset Maps in Plotly (Python)

I am currently trying to plot a few maps by using Plotly Express and Mapbox in Python.

I need to have a big map with the country and, next to it, an inset map with a “zoom” to a particular region (see Image attached as an example) INSET MAP EXAMPLE.

I managed to plot the bigger map (i.e. the whole country) but can’t find a proper way to create the inset map.

I tried to make 2 subplot (1 row, 2 cols), but did not work as expected. Also tried to plot two figures (one bigger, the whole country, and one smaller, the inset map) at the same time, but the two of them “collide” (the inset map turns out to be on top of the other one).

Any idea or possible turnaround for this?

Thank you.

Advertisement

Answer

  • have used dash to enable callbacks from main choropeth to update inset choropeth (The way I have structured dash HTML means it is outset…)
  • to bring it all together I have used some geo mapping data from UK government sources
  • have just modified center of choropeth in callback. Could also modify zoom and/or range

get some geo data

JavaScript

build base figure

JavaScript

dash app

JavaScript

output

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement