Skip to content

Points & Labels

geoplot-themes natively supports plotting point data (e.g., cities, sample locations) and smartly repelling their labels so they do not overlap, utilizing the incredible ggrepel package under the hood.

Basic Point Plotting

You can pass point data (either an .shp file or a spatial .csv) to points_data.

python
import geoplot_themes as gpt

gpt.plot_map_r(
    raster_data="base_raster.tif",
    points_data="cities.shp",
    output_path="cities_map.png"
)

By default, this will plot simple red dots.

Styling & Coloring Points

If your point data has attributes (like population size or category), you can color the points by specifying points_color_column.

python
gpt.plot_map_r(
    raster_data="base_raster.tif",
    points_data="sampling_locations.shp",
    points_color_column="pH_level",       # The column to base colors on
    points_discrete=False,                # Set to True if it's categorical data
    colormap="neon",                      # The colormap to apply
    output_path="samples.png"
)

Adding Non-Overlapping Labels

Adding labels to maps usually results in a cluttered mess. We use geom_label_repel to automatically push labels away from each other and away from the data points, drawing neat little connecting lines.

Just specify points_label_column.

python
gpt.plot_map_r(
    vector_data="country_borders.shp",
    points_data="capital_cities.shp",
    points_label_column="city_name",      # Column containing the text!
    points_color_column="population",
    theme="retro_blueprint",
    output_path="capitals.png"
)

What happens behind the scenes: The engine draws your points, calculates the collisions of your text labels, repels them into empty space, and draws a beautiful grey50 segment connecting the label back to the exact coordinate. All automatically!

Released under the MIT License.