Skip to content

Open in Colab

Bivario with Lonboard

image.png

Bivario integrates with lonboard in viz_bivariate_data function. It is a wrapper around lonboard.viz function.

By default, the legend is attached to the map result as a LonboardMapWithLegend object with attributes m (lonboard.Map) and legend function (will generate a bivariate legend and display it). The object automatically displays a lonboard map in Jupyter context.

from bivario import viz_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

viz_bivariate_data function required only three inputs: data (any compatible with lonboard.viz function) and columns a and b.

By default, a bivariate legend is attached, but resulting object will display lonboard.Map in the result.

viz_bivariate_data(gdf, "morning_starts", "morning_ends")

Access the legend

x = viz_bivariate_data(gdf, "morning_starts", "morning_ends")
print("Return class:", type(x))
x.legend()
Return class: <class 'bivario.lonboard.LonboardMapWithLegend'>





<Axes: xlabel='morning_ends', ylabel='morning_starts'>

png

Get only the map

m = viz_bivariate_data(gdf, "morning_starts", "morning_ends", legend=False)
type(m)
lonboard._map.Map

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.

x = viz_bivariate_data(gdf, "morning_starts", "morning_ends", dark_mode=True, cmap="rosewood_pine")
x
x.legend()
<Axes: xlabel='morning_ends', ylabel='morning_starts'>

png

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

x = viz_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=False,  # Disable categorization - numerical mode
)
x
x.legend()
<Axes: xlabel='morning_ends', ylabel='morning_starts'>

png

Mixed number of classes and schemes

x = viz_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=("NaturalBreaks", "JenksCaspall"),
    k=(4, 3),
)
x
x.legend()
<Axes: xlabel='morning_ends', ylabel='morning_starts'>

png

Mixed numerical and categorical modes

x = viz_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    scheme=(True, False),
)
x
x.legend()
<Axes: xlabel='morning_ends', ylabel='morning_starts'>

png

Add lonboard kwargs

viz_bivariate_data(
    gdf,
    "morning_starts",
    "morning_ends",
    map_kwargs={"show_tooltip": True},
    polygon_kwargs={"stroked": True},
)