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()