Hi everyone
I want to plot a map with plotly choropleth function. There is a parameter featureidkey to set locations into a key but in my json and dataframe it does not work. If i dont set this parameter map is fine but i want to set a key for each id.
import json
with open('Covid-19/tr-cities-utf8.json', encoding="utf-8") as response:
counties = json.load(response)
counties["features"][0]
{‘geometry’: {‘type’: ‘MultiPolygon’,
‘coordinates’: [[[[35.279026031494084, 36.64069366455101],
[35.28180694580078, 36.6390266418457],
[35.282917022705135, 36.636806488037166],
[35.27819442749029, 36.640140533447266],
[35.279026031494084, 36.64069366455101]]],
[[[35.27152633666998, 36.64485931396507],
[35.274028778076456, 36.64319610595709],
[35.274028778076456, 36.64208221435558],
[35.27125167846697, 36.64319610595709],
[35.27152633666998, 36.64485931396507]]],
[[[35.20735931396513, 36.65069580078119],
[35.2093048095706, 36.64986038208025],
[35.20958328247099, 36.64930725097685],
[35.206249237060604, 36.649028778076456],
[35.20735931396513, 36.65069580078119]]],
[[[35.21180725097656, 36.65541839599638],
[35.212081909179744, 36.65319442749046],
[35.21152877807634, 36.6529159545899],
[35.20958328247099, 36.65513992309582],
[35.21180725097656, 36.65541839599638]]],
[[[35.21347045898466, 36.659862518310774],
[35.21402740478527, 36.65874862670927],
[35.21069335937517, 36.65902709960943],
[35.21097183227556, 36.659862518310774],
[35.21347045898466, 36.659862518310774]]],
[[[35.20958328247099, 36.67874908447283],
[35.212360382080135, 36.677639007568644],
[35.212360382080135, 36.67680740356468],
[35.20847320556646, 36.6781959533692],
[35.20958328247099, 36.67874908447283]]],
[[[35.5912513732913, 36.704029083252124],
[35.5915260314942, 36.6995849609375],
[35.59069442749018, 36.6995849609375],
[35.589862823486385, 36.70319366455078],
[35.5912513732913, 36.704029083252124]]],
[[[35.60680389404291, 36.70541763305687],
[35.60625076293951, 36.700973510742415],
[35.6012496948245, 36.70019912719721],
[35.60514068603533, 36.70541763305687],
[35.60680389404291, 36.70541763305687]]],
[[[35.68264007568365, 36.716251373291016],
[35.67958450317383, 36.71263885498075],
[35.67736053466825, 36.7140274047851],
[35.680973052978516, 36.716251373291016],
[35.68264007568365, 36.716251373291016]]],
[[[35.69708251953142, 36.72735977172874],
[35.70291519165045, 36.724304199219034],
[35.70291519165045, 36.72347259521507],
[35.69736099243181, 36.72375106811546],
[35.69708251953142, 36.72735977172874]]],
[[[36.329639434814624, 37.92000961303711],
[36.31517028808622, 37.88559722900396],
[36.31903839111345, 37.83251953125],
[36.36219787597662, 37.75340270996094],
[36.302368164062614, 37.651248931884936],
[36.153835296630916, 37.63694381713884],
[36.033290863037166, 37.57089233398443],
[35.88317108154325, 37.35688018798834],
[35.881771087646484, 37.241584777832145],
[35.904296875000114, 37.20827102661144],
[35.85282516479492, 37.12870788574219],
[35.87482452392595, 37.121696472168026],
[36.000972747802734, 37.17415237426786],
[36.03230667114258, 37.15906143188488],
[36.061447143554744, 37.108856201171875],
[36.04160690307617, 37.025554656982536],
[35.94699859619146, 36.95690536499052],
[35.91258621215826, 36.90350723266613],
[35.93404769897478, 36.87985992431646],
[35.84180450439453, 36.795139312744254],
[35.7945823669433, 36.765693664551065],
[35.666805267333984, 36.76708221435547],
[35.6270828247072, 36.74569320678734],
[35.60930633544939, 36.71430587768549],
[35.61291503906244, 36.73208236694336],
[35.60319519042969, 36.727085113525334],
[35.5995826721192, 36.69985961914091],
[35.5915260314942, 36.71097183227562],
[35.563194274902344, 36.71263885498075],
[35.55430603027372, 36.6995849609375],
[35.570137023926065, 36.70652770996122],
[35.584583282470646, 36.67958450317394],
[35.6295814514163, 36.721527099609375],
[35.62430572509794, 36.733749389648665],
[35.654304504394474, 36.739860534668026],
[35.64541625976568, 36.70763778686518],
[35.65680694580095, 36.72902679443365],
[35.65402603149414, 36.70791625976557],
[35.70652770996122, 36.71319580078131],
[35.704303741455135, 36.72319412231468],
[35.7234725952149, 36.71263885498075],
[35.64513778686529, 36.66847229003906],
[35.62180709838884, 36.604305267334155],
[35.581806182861385, 36.59069442749052],
[35.565971374512, 36.56486129760748],
[35.41819381713873, 36.590137481689396],
[35.339027404785156, 36.538471221924],
[35.329582214355526, 36.56791687011713],
[35.32208251953142, 36.572360992431754],
[35.34624862670904, 36.60347366333036],
[35.285137176513615, 36.62680435180664],
[35.28791809082048, 36.64347076416033],
[35.27097320556658, 36.65208435058611],
[35.2640266418457, 36.639305114746264],
[35.24902725219738, 36.654026031494254],
[35.27152633666998, 36.66180419921875],
[35.25097274780302, 36.6781959533692],
[35.18069458007841, 36.69291687011719],
[35.163471221924, 36.67597198486351],
[35.17597198486345, 36.66152954101574],
[35.273471832275675, 36.60874938964861],
[35.3245849609375, 36.55875015258812],
[34.997917175293026, 36.713470458984546],
[34.91521453857422, 36.724861145019645],
[34.949817657470646, 36.7540168762207],
[35.034801483154354, 36.770996093750284],
[35.06715011596697, 36.81790924072271],
[35.06958389282255, 36.8526496887207],
[35.05463027954107, 36.97039413452154],
[35.00078582763683, 37.041458129882926],
[34.92519378662115, 37.0896911621096],
[34.90010833740263, 37.17629623413086],
[34.78625869750982, 37.379280090332145],
[34.78827667236334, 37.465160369873104],
[34.860763549804744, 37.525032043456974],
[34.85847854614258, 37.57877349853527],
[34.81658554077154, 37.65838241577154],
[34.826660156250284, 37.684917449951286],
[34.86949157714844, 37.71004486083979],
[35.02579116821306, 37.69889450073242],
[35.08160018920927, 37.718662261963004],
[35.21365356445324, 37.83214187622076],
[35.20755767822294, 37.91330337524414],
[35.24167633056646, 37.95356369018572],
[35.45680999755865, 37.91956710815424],
[35.621017456054744, 37.95576095581066],
[35.680976867676065, 38.05966186523432],
[36.01338195800787, 38.185642242431584],
[36.161430358887, 38.4135093688966],
[36.30536651611334, 38.463748931884766],
[36.37761306762707, 38.46636962890625],
[36.42207336425781, 38.442195892333984],
[36.49144363403326, 38.31632614135742],
[36.42615890502947, 38.25278854370117],
[36.33535766601574, 37.99667358398449],
[36.329639434814624, 37.92000961303711]]]]},
‘properties’: {‘name’: ‘Adana’},
‘id’: 1,
‘type’: ‘Feature’}
#Turkey map
import plotly.express as px
fig = px.choropleth(eachcitydf, geojson=counties, color='Number of Case',
color_continuous_scale="Viridis_R",
range_color=(0,300),
locations = "id",
scope="asia",
labels={'Number of Case':'# of Case'},
featureidkey="properties.name",
center = {"lat": 39.925533, "lon": 32.866287},
projection="mercator")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_geos(fitbounds="locations", visible=False)
fig.show()
I tried all combinations for name key but it does not work. Could someone help me ?