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

Italian Chart Not Created

Hi guys,

Am ne to plotly. I want to create a chart with same data as you did for US under this link: https://plot.ly/python/choropleth-maps/

The issue is that i am not sure how to do that, as there were some errors e.g The 'locationmode' property is an enumeration that may be specified as: - One of the following enumeration values: ['ISO-3', 'USA-states', 'country names']

This is my code. Also if you can guide on what i am doing wrong, i would appreciate it a lot!

import plotly
import plotly.plotly as py
import pandas as pd
import plotly.tools as plotly_tools
plotly.tools.set_credentials_file(username='user', api_key='pass')

df = pd.read_csv('https://www.downloadexcelfiles.com/sites/default/files/docs/list-cities-italy-50j.csv')

for col in df.columns:
    df[col] = df[col].astype(str)

scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
            [0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]

df['text'] = df['City'] + '<br>' +\
    'City '+df['City']+' 2011 Census '+df['2011 Census']+'<br>'+\
    '1981 Census'+df['1981 Census']+'2011 Census' + df['2011 Census']+'<br>'+\
    'Region '+df['Region']

data = [ dict(
        type='choropleth',
        colorscale = scl,
        autocolorscale = False,
        locations = df['City'],
        # z = df['2011 Census'].astype(float),
        locationmode = 'ITA',
        text = df['text'],
        marker = dict(
            line = dict (
                color = 'rgb(255,255,255)',
                width = 2
            ) ),
        colorbar = dict(
            title = "Millions Euro")
        ) ]

layout = dict(
        title = '2011 Agriculture Exports by Italy<br>(Hover for breakdown)',
        geo = dict(
            scope='ita',
            projection=dict( type='ita' ),
            showlakes = True,
            lakecolor = 'rgb(255, 255, 255)'),
             )
    
fig = dict( data=data, layout=layout )
py.plot( fig, filename='d3-cloropleth-map-ita' )

Hi! The locationmode variable actually refers to the string description of each region in the map. If you’re looking to create a chloropleth map for Italy, then this might help you out:

(Note that it’s actually for the R programming language, but doing something similar might work.)

Thank you! I don’t know R, i know Python!

@ionutc I also encountered this problem