Skip to content

Open in Colab

Bivario with Folium

image-2.png

Bivario integrates with Folium in explore_bivariate_data function. It is a wrapper around geopandas.explore function.

It expects a GeoDataFrame input and adds a legend in the corner that has similar look as other Leaflet components.

from bivario import explore_bivariate_data
from bivario.example_data import nyc_bike_trips
gdf = nyc_bike_trips()
gdf
h3 morning_starts morning_ends afternoon_starts afternoon_ends geometry
0 617733120577503231 903 440 760 803 POLYGON ((-73.88768 40.876, -73.88979 40.87506...
1 617733120577765375 908 342 1259 1695 POLYGON ((-73.88544 40.87341, -73.88755 40.872...
2 617733120578027519 366 860 1180 775 POLYGON ((-73.89196 40.87589, -73.89408 40.874...
3 617733120578289663 1848 1338 2768 2401 POLYGON ((-73.88972 40.8733, -73.89183 40.8723...
4 617733120578551807 1387 759 2208 2456 POLYGON ((-73.88563 40.8787, -73.88774 40.8777...
... ... ... ... ... ... ...
1564 617733152329433087 1239 925 1121 1310 POLYGON ((-74.00425 40.67719, -74.00635 40.676...
1565 617733152329695231 1770 2077 3805 3374 POLYGON ((-74.00201 40.67461, -74.00411 40.673...
1566 617733152329957375 1544 1399 1888 2300 POLYGON ((-74.00852 40.67707, -74.01062 40.676...
1567 617733152333627391 2264 2899 8916 8258 POLYGON ((-74.01503 40.67954, -74.01713 40.678...
1568 617733152333889535 1937 2825 7320 6637 POLYGON ((-74.01279 40.67696, -74.01489 40.676...

1569 rows × 6 columns

Basic usage

explore_bivariate_data function required only three inputs: gdf (GeoDataFrame) and columns a and b.

By default, a bivariate legend is attached and shown in the bottom left corner.

explore_bivariate_data(gdf, "morning_starts", "morning_ends")

Dark mode

With dark mode, the basemap is automatically changed to OpenFreeMap Dark and colourmap automatically swaps high and low colours.

You can also select a colourmap using a str name to load a predefined palette.

explore_bivariate_data(gdf, "morning_starts", "morning_ends", dark_mode=True, cmap="rosewood_pine")

Change legend

Legend look can be changed: position, size and background and border.

explore_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    legend_loc="tr",  # top-right
    legend_size_px=300,
    legend_background=False,
    column_a_label="Morning starts",
    column_b_label="Morning ends",
)

Change classification scheme

By default, Mapclassify NaturalBreaks algorithm is applied to the inputs with 5 classes.

This can be changed or disabled for both inputs independently.

Numerical mode

explore_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=False,  # Disable categorization - numerical mode
)

Mixed number of classes and schemes

explore_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=("NaturalBreaks", "JenksCaspall"),
    k=(4, 3),
)

Mixed numerical and categorical modes

explore_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=(True, False),
)

Add folium kwargs

explore_bivariate_data(gdf, "morning_starts", "morning_ends", zoom_start=12)