I tried to see if I could actually do it. geojosn got it from geojson.cn and I created the user data properly and used it for the map. Place name annotations were specified using go.Scattertermapbox. And if you annotate text after go.Choroplethmapbox, there are cases where it is hidden in the mapbox place name display. Therefore, the place name is annotated first, and the choropleth map is annotated after.
from urllib import request
import json
url='https://geojson.cn/api/data/220000.json'
with request.urlopen(url) as f:
jilin = json.load(f)
names = []
for n in range(len(jilin['features'])):
name = jilin['features'][n]['properties']['name']
names.append(name)
names
['้ฟๆฅ', 'ๅๆ', 'ๅๅนณ', '่พฝๆบ', '้ๅ', '็ฝๅฑฑ', 'ๆพๅ', '็ฝๅ', 'ๅปถ่พน']
lats = []
lons = []
for n in range(len(jilin['features'])):
lat_lon = jilin['features'][n]['properties']['center']
lats.append(lat_lon[1])
lons.append(lat_lon[0])
import random
import pandas as pd
import numpy as np
df = pd.DataFrame({'name':names, 'values': np.random.randint(0,100,9)})
import plotly.express as px
import plotly.graph_objects as go
lons = [125.3245, 122.841114]
lats = [43.886841, 45.619026]
text= ["Changchun","Baicheng"]
mapbox_token = open("mapbox_api_key.txt").read()
fig = go.Figure()
fig.add_trace(go.Scattermapbox(lat=lats,
lon=lons,
mode='text+markers',
text=text,#df['name'].to_list(),
textposition='top left',
textfont=dict(color='blue'),
marker_size=5,
marker_color='blue'
))
fig.add_trace(go.Choroplethmapbox(geojson=jilin,
locations=df['name'],
z=df['values'],
featureidkey="properties.name",
colorscale="Reds",
zmin=0,
zmax=100,
marker_opacity=0.8,
marker_line_width=0
))
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(mapbox=dict(
center={"lat": 43.5, "lon": 126},
accesstoken=mapbox_token,
zoom=5,
style="light"
))
fig.show()