105 vector time slider
Visualizing vector data with time attributes
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install -U leafmap
# %pip install -U leafmap
In [2]:
Copied!
from leafmap import leafmap
import geopandas as gpd
from leafmap import leafmap
import geopandas as gpd
In [3]:
Copied!
url = "https://github.com/opengeos/datasets/releases/download/us/zillow_home_value_index_by_county_ca.geojson"
url = "https://github.com/opengeos/datasets/releases/download/us/zillow_home_value_index_by_county_ca.geojson"
In [4]:
Copied!
data = gpd.read_file(url)
data.head(2)
data = gpd.read_file(url)
data.head(2)
Out[4]:
| place | RegionID | SizeRank | RegionName | RegionType | StateName | State | Metro | StateCodeFIPS | MunicipalCodeFIPS | ... | 2024-06-30 | 2024-07-31 | 2024-08-31 | 2024-09-30 | 2024-10-31 | 2024-11-30 | 2024-12-31 | 2025-01-31 | index | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | geoId/06037 | 3101 | 0 | Los Angeles County | county | CA | CA | Los Angeles-Long Beach-Anaheim, CA | 06 | 037 | ... | 853328 | 856958 | 862129 | 868712 | 873819 | 877921 | 881313 | 880547 | 218.0 | MULTIPOLYGON (((-118.67855 33.02634, -118.6748... | 
| 1 | geoId/06073 | 2841 | 4 | San Diego County | county | CA | CA | San Diego-Chula Vista-Carlsbad, CA | 06 | 073 | ... | 931835 | 933267 | 932833 | 932389 | 931683 | 931874 | 932380 | 932486 | 212.0 | POLYGON ((-117.61109 33.33401, -117.57155 33.3... | 
2 rows × 313 columns
In [5]:
Copied!
legend_dict = {
    "[ 0,  200000]": "#e6f3ff",  # Very light blue
    "( 200000,  400000]": "#deebf7",  # Light blue
    "( 400000,  600000]": "#9ecae1",  # Medium blue
    "( 600000,  800000]": "#4292c6",  # Medium-dark blue
    "( 800000, 1000000]": "#2171b5",  # Dark blue
    "( 1000000, 2000000]": "#084594",  # Very dark blue
    "Nodata": "#f0f0f0",  # Light gray
}
legend_dict = {
    "[ 0,  200000]": "#e6f3ff",  # Very light blue
    "( 200000,  400000]": "#deebf7",  # Light blue
    "( 400000,  600000]": "#9ecae1",  # Medium blue
    "( 600000,  800000]": "#4292c6",  # Medium-dark blue
    "( 800000, 1000000]": "#2171b5",  # Dark blue
    "( 1000000, 2000000]": "#084594",  # Very dark blue
    "Nodata": "#f0f0f0",  # Light gray
}
In [6]:
Copied!
gdf = leafmap.color_code_dataframe(data, legend_dict=legend_dict)
gdf.head(2)
gdf = leafmap.color_code_dataframe(data, legend_dict=legend_dict)
gdf.head(2)
Out[6]:
| place | RegionID | SizeRank | RegionName | RegionType | StateName | State | Metro | StateCodeFIPS | MunicipalCodeFIPS | ... | 2024-06-30 | 2024-07-31 | 2024-08-31 | 2024-09-30 | 2024-10-31 | 2024-11-30 | 2024-12-31 | 2025-01-31 | index | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | geoId/06037 | 3101 | #e6f3ff | Los Angeles County | county | CA | CA | Los Angeles-Long Beach-Anaheim, CA | 06 | 037 | ... | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #e6f3ff | MULTIPOLYGON (((-118.67855 33.02634, -118.6748... | 
| 1 | geoId/06073 | 2841 | #e6f3ff | San Diego County | county | CA | CA | San Diego-Chula Vista-Carlsbad, CA | 06 | 073 | ... | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #2171b5 | #e6f3ff | POLYGON ((-117.61109 33.33401, -117.57155 33.3... | 
2 rows × 313 columns
In [7]:
Copied!
m = leafmap.Map()
m
m = leafmap.Map()
m
In [8]:
Copied!
m.add_gdf_time_slider(gdf, time_interval=0.05, zoom_to_layer=True)
m.add_legend(title="Median Home Value", legend_dict=legend_dict)
m.add_gdf_time_slider(gdf, time_interval=0.05, zoom_to_layer=True)
m.add_legend(title="Median Home Value", legend_dict=legend_dict)