In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lets_plot import *
In [2]:
LetsPlot.setup_html()

Draw GeoDataFrame on plot

In [3]:
from geopandas import GeoDataFrame
from shapely.geometry import MultiPolygon, Polygon, LinearRing, Point, mapping
In [4]:
POINT = Point(-5, 17)

POLYGON = Polygon(
    LinearRing([(1, 1), (1, 9), (9, 9), (9, 1)]),
    [LinearRing([(2, 2), (3, 2), (3, 3), (2, 3)]),
     LinearRing([(4, 4), (6, 4), (6, 6), (4, 6)])]
    )

MULTIPOLYGON = MultiPolygon([
    Polygon(LinearRing([(11, 12), (13, 14), (15, 13)]))
    ])
In [5]:
gdf = GeoDataFrame(
    data={'id': ['A', 'B', 'C'],
          'coord': [POINT, POLYGON, MULTIPOLYGON]},
    geometry='coord')
In [6]:
ggplot() + geom_polygon(aes(fill = 'id'), gdf)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Temp/ipykernel_9592/3737669046.py in <module>
----> 1 ggplot() + geom_polygon(aes(fill = 'id'), gdf)

TypeError: geom_polygon() takes from 0 to 1 positional arguments but 2 were given

Mapping doesn't work for DataFrame in map

In [ ]:
ggplot() + geom_polygon(aes(fill = 'id'), map = gdf)
In [ ]:
ggplot() + geom_polygon(map = gdf)
In [ ]:
df = pd.DataFrame(
    {'name': ['A', 'B', 'C'],
     'value': [42, 23, 87]})
In [ ]:
ggplot() + geom_polygon(aes(fill = 'value'), df, map = gdf, map_join=('name', 'id'))

Geom kinds that support GeoDataFrame

In [ ]:
ggplot() + geom_polygon(data = gdf)
In [ ]:
ggplot() + geom_point(aes(color='id'), gdf, size=5)
In [ ]:
ggplot() + geom_rect(aes(fill='id'), gdf)
In [ ]:
ggplot() + geom_path(data = gdf)
In [ ]:
ggplot() + geom_map(map = gdf)

Problems

In [ ]:
ggplot() + geom_map(data = gdf)

Error message contains autogenerated column "__key__". It's ok.

In [ ]:
ggplot() + geom_polygon(aes(fill = 'id'), gdf)