Black Lives Matter. Please consider donating to Black Girls Code today.

go.Scattergeo with geojson and featureidkey: the map is not drawn

I’ve problem similar to another problem submitted to the forum and solved a few months ago and therefore I’m referring to previous post and to the data used in it.

In the reply to this post


Emmanuelle showed how to use geojson and featureidkey attributes in a go.Choropleth trace, as in following code

import json
from urllib.request import urlopen
import pandas as pd
import numpy as np
import plotly.graph_objects as go
df = pd.read_csv(‘https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/data.csv’)
counties = json.load(open(“counties.json”))
URL = “https://raw.githubusercontent.com/FBosler/covid19-dash-app/master/functions/counties.json
with urlopen(URL) as response:
counties = json.load(response)
trace = go.Choropleth(
geojson=counties,
z=np.log10(df[‘infected’]),
locations=df[‘Landkreis’],
featureidkey=“properties.NAME_3”)
fig = go.Figure(data=trace)
fig.update_geos(fitbounds=“locations”)
fig.show()

I’m trying to create a go.Scattergeo plot with geojson and featureidkey attributes (see following code), but the output is not the expected one. The markers are shown and the map defined in geojosn file is not shown. What is missing in my example?
Next step will be to animate the scatter plot, with the size of the markers changing in each frame, but by now I’m trying to draw a static plot.
Thanks in advance for your help

Mauro

trace = go.Scattergeo(
marker=dict(size=df[‘infected’],
sizemode=“area”),
geojson=counties,
locations=df[‘Landkreis’],
featureidkey=“properties.NAME_3”)
fig = go.Figure(data=trace)
fig.update_geos(fitbounds=“locations”)
fig.show()

problem solved, two traces are required, that is:

  • a static go.Choropleth trace with the map
  • a dynamic go.Scattergeo bubble trace, with a set of frames for animation

If anyone is interested, a draft solution is here:

https://github.com/to-mg/someTests/blob/main/go.Choropleth.Scattegeo.animated.py