1

I am trying to use plotly choropleth to draw the map, lets say for a random variable of num for each of the feature regions of the map in Italy. However, it does not work. below is the code that I use:

I have downloaded the GeoJSON files for Italy from here.

import random
import pandas as pd
import plotly.express as px
import plotly.io as pio
import json
pio.renderers.default='browser'

with open('it-all.geo.json') as f:
     geojson = json.load(f)

n_provinces = len(geojson['features'])

province_names = [geojson['features'][k]['properties']['name'] for k in range(n_provinces)]

randomlist = []
for i in range(0,110):
    n = random.randint(1,30)
    randomlist.append(n)

datadata = pd.DataFrame({'province':province_names, 'num':randomlist}) 

fig = px.choropleth(datadata, geojson=geojson, color="num",
                    locations="province", featureidkey="properties.name",
                    color_continuous_scale="Viridis")

fig.show()

What I am getting is a mixed shape map as below. Can anyone let me know what I am doing wrong? enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.