# Erstes Beispiel von "https://plotly.com/python/mapbox-county-choropleth/" 
# Offiziele Plotly Seite Beispiel

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

# print(counties["features"][0])

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

#print(df.head())
#print(df.dtypes)

import plotly.express as px

fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           mapbox_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.5,
                           labels={'unemp':'unemployment rate'}
                          ) # Genau was ich auch mache, außer das ich featureidkey="properties.NUTS" noch dazu nutze -> Damit NUTS als key genutzt werden kann was unter properties liegt
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()