Cannot display changes over time in map in Pydeck in Jupyter Notebook

74 Views Asked by At

The map created using Pydeck in Jupyter Notebook does not show any updates. It literally stays static.

I followed along this guide https://www.youtube.com/watch?v=i-dGU80hNOw and tried to recreate "Visualization over time" section, however it did not work for me. The year is changing over time but not the map. The notebook is here https://colab.research.google.com/drive/1Ha9X6G0FrqTJWpDkz_iH9Vuwgp07gBy1#scrollTo=2wYQhNdMo8Kk.

The code is below:

import geopandas as gpd
import ipywidgets
import time
import pydeck as pdk

url = 'https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/historical-hurricanes.geo.json'
gdf = gpd.read_file(url)
gdf = gdf[['name', 'geometry', 'year', 'maximum_sustained_wind']]
gdf['year'] = gdf['year'].astype('int32')

layer = pdk.Layer(
    'GeoJsonLayer',
    data=gdf,
    stroked=False,
    filled=True,
    line_width_scale=20,
    line_width_min_pixels=2,
    get_line_color='[maximum_sustained_wind, 0, maximum_sustained_wind, 200]',
    get_radius=10,
    get_line_width=1
)

deck = pdk.Deck(layer, map_style=pdk.map_styles.LIGHT)
year = ipywidgets.HTML()
display(year)
display(deck.show())

for i in range(gdf.year.min(), gdf.year.max() + 1):
  deck.layers[0].data = gdf[gdf['year'] == i]
  deck.update()
  year.value = f'<b>{i}</b>'
  time.sleep(1)

Sorry, if the error is small, I am new to pydeck and Jupyter widgets.

0

There are 0 best solutions below