Choropleth Map Python with Date Slider

430 views Asked by At

Hello this is my first post on stackoverflow so bear with me please! I am trying to produce a Choropleth map with a Date slider. Everything I have found has shown a year slider. I have my dataframe as desired and I have imported the counties/fips. This is working as you can see in the link below. I have a date field in the data frame. My question is how do I add that to the map as a slider so a user can drag the slider and see the county color shade change over time.

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)

df = pd.read_csv('time_series_covid19_cases_deaths_NJ.csv', parse_dates=['Date'])

fig = px.choropleth_mapbox(df,                           

geojson=counties,                           

locations='FIPS',

color='Cases',

hover_name='Admin2',

color_continuous_scale="Viridis",

#range_color=(0, 12),
                           
mapbox_style="carto-positron",
                           
zoom=6, center = {"lat": 39.5583, "lon": -74.4057},
                           
opacity=0.5,
                           
labels={'Cases':'Confirmed Cases'}
                          )

fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})

fig.show()

Map without slider

0

There are 0 answers