Skip to content

ScatterPlotLayer (points)

In this notebook we will demonstrate using spatial polars to visualize spatial data on a Lonboard map usign a scatterplot layer to visualize the point data.

Note

This example makes use the geodatasets python package to access some spatial data easily.

Calling geodatasets.get_path() will download data the specified data to the machine and return the path to the downloaded file. If the file has already been downloaded it will simply return the path to the file. See downloading and caching for further details.

Creating a ScatterplotLayer

The following cell will read the geoda home sales point dataset into a dataframe and create a Lonboard ScatterplotLayer

Creating a scatterplotlayer
import geodatasets
from lonboard import Map
from spatial_polars import read_spatial

home_sales_df = read_spatial(geodatasets.get_path("geoda.home_sales"))  # (1)!

scatterplotlayer = home_sales_df.spatial.to_scatterplotlayer(  # (2)!
    fill_cmap_col="floors",  # (3)!
    fill_cmap_type="categorical",  # (4)!
    fill_cmap={1: (255, 0, 0), 2: (0, 255, 0), 3: (0, 0, 255)},  # (5)!
    radius=250,  # (6)!
    stroked=False,  # (7)!
)

scatterplotlayer_map = Map(layers=[scatterplotlayer])  # (8)!
scatterplotlayer_map
  1. Read the geoda.home_sales geodataset
  2. Create the scatterplotlayer
  3. Use the values in the 'floors' column to set the color of the points in the layer
  4. Use a categorical color mapping dictionary to set the color of the points
  5. If the number of floors is 1 the point will be red, two floors will be green, and three will be blue
  6. The number of meters for the point symbols on the map
  7. The points will not have an outline drawn around them
  8. Show the scatterplotlayer on a map

Note

If you're interested in using a continuous colormap instead of a categorical, head over to the polygonlayer example to check out how we can do it.