Download notebook (.ipynb)

GeoDataFrame with texts and labels#

GeoDataFrame is supported natively in the data parameter for geom_label()/geom_label_repel() and geom_text()/geom_text_repel().

import geopandas as gpd

from lets_plot import *
LetsPlot.setup_html()
base_url = "https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/"
world_gdf = gpd.read_file(base_url + "naturalearth_lowres/naturalearth_lowres.shp")
cities_gdf = gpd.read_file(base_url + "naturalearth_cities/naturalearth_cities.shp")
ggplot() + \
    geom_map(map=world_gdf, fill="light_green", alpha=.3) + \
    geom_point(map=cities_gdf, color="dark_slate_gray", size=3) + \
    geom_label_repel(aes(label="name"), data=cities_gdf, color="dark_slate_gray", seed=42, max_iter=200) + \
    coord_map(xlim=[-10.5, 44.0], ylim=[37.0, 60.5]) + \
    theme(axis="blank", panel_grid="blank") + \
    ggsize(800, 600)