Hi everybody, im trying to use this methods to build one map for Portugal, but somehow it doesnt even show colors, if somebody could help me it would be very appreciated. Hereās my code:
import plotly.graph_objects as go
import json
import urllib.request
import random
def read_geojson(url):
with urllib.request.urlopen(url) as url:
jdata = json.loads(url.read().decode())
return jdata
url=āhttps://raw.githubusercontent.com/nmota/caop_GeoJSON/8d86a69dd0ebc1f11316bc7d55bd56102b9e1e7c/DistritosGeoJSON_2015.geojsonā
r = requests.get(url)
decoded_data=codecs.decode(r.text.encode(), āutf-8-sigā)
jdata= json.loads(decoded_data)
thelist = jdata[āfeaturesā]
locations = [ item[āpropertiesā][āDIā] for item in thelist ]
print('locations: ', locations)
randomlist =
for i in range(0,len(locations)):
n = random.randint(0,10)
randomlist.append(n)
z = randomlist
print('z: ', z)
mapboxt = open(".mapbox_token").read().rstrip()
print('mapboxt: ', mapboxt)
fig= go.Figure(go.Choroplethmapbox(z=z, # This is the data.
locations=locations,
colorscale=āredsā,
colorbar=dict(thickness=20, ticklen=3),
geojson=jdata,
text=locations,
hoverinfo=āallā,
marker_line_width=1, marker_opacity=0.75))
fig.update_layout(title_text= āPortugal Mapā,
title_x=0.5, width = 700,height=700,
mapbox = dict(center= dict(lat=39.425049, lon=-7.944620),
accesstoken=mapboxt,
style=ācarto-positronā,
zoom=5.6,
));
fig.show()