Or, for coffee fans, a map of all Starbucks in the UK: # no GINI for that country: return default color color = ( 0, 0, 0, 0.3) Return gmaps_color # Calculate a color for each GeoJSON feature colors = įor feature in countries_geojson:Ĭountry_name = feature # transform from a matplotlib color to a valid CSS color gmaps_color = to_hex( mpl_color, keep_alpha = False) """ Convert the GINI coefficient to a color """ # make gini a number between 0 and 1 normalized_gini = ( gini - min_gini) / gini_range # invert gini so that high inequality gives dark color inverse_gini = 1.0 - normalized_gini # transform the gini coefficient to a matplotlib color mpl_color = viridis( inverse_gini) Gini_range = max_gini - min_gini def calculate_color( gini): load_dataset( 'gini') # 'rows' is a list of tuples country2gini = dict( rows) # dictionary mapping 'country' -> gini coefficient min_gini = min( country2gini. load_geometry( 'countries') # Load GeoJSON of countries rows = gmaps. configure( api_key = "AI.") # Your Google API key countries_geojson = gmaps. colors import to_hex import gmaps import gmaps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |