How to create a choroplet and scatter plots maps

Hi @Gillopy, welcome to the forum.

I think you can solve your problem by reading this thread: Annotations on plotly Choropleth + choropleth_mapbox + Scattermapbox - #5 by hoatran

We don’t have your data so you can refer below code:

import plotly.express as px
import geopandas as gpd
import plotly.graph_objects as go
import pandas as pd
from urllib.request import urlopen
import json

europe = pd.read_csv('https://raw.githubusercontent.com/softhints/Pandas-Exercises-Projects/main/data/europe_pop.csv')

lats = europe['lat']
lons = europe['lon']
text= (europe['pop_est']/1000000).round(decimals=0).astype(str)

with urlopen('https://raw.githubusercontent.com/leakyMirror/map-of-europe/master/GeoJSON/europe.geojson') as response:
    counties = json.load(response)
    
fig = go.Figure()
fig.add_trace(go.Scattermapbox(lat=lats,
                               lon=lons,
                               mode='text+markers',
                               text=text,
                               textfont=dict(
                                   family="san serif",
                                   size=15),
                               textposition='top center',
                               marker_size=europe['pop_est']/1000000))

fig.add_trace(go.Choroplethmapbox(geojson=counties,
                                  locations=europe['name'],
                                  z=europe['pop_est'],
                                  colorscale="Reds",
                                  featureidkey="properties.NAME",
                                  marker_opacity=0.8,
                                  marker_line_width=0))

fig.update_layout(title_text ='Europe', 
                  title_x =0.5, 
                  width=1200, 
                  height=1200, 
                  mapbox = dict(center= dict(lat=52.370216, lon=4.895168),            
                                 accesstoken= "your_token",
                                 zoom=3,
                                 style="light"
                               )
                 )
fig.show()

*Note: You have to add your map_box token in accesstoken

2 Likes