[Python] Change contextily basemap size

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am creating a program that maps out postal codes of my choosing and then applies a colormap based on some conditions. The issue I am running into is that I would like the resulting image to always be specific dimensions. I am using data from https://www.suche-postleitzahl.org/downloads.

    Currently, I am plotting my postal codes from a geodataframe:

    import geopandas as gdp
    import contextily as ctx
    import matplotlib.pyplot as plt

    postal_codes = [10117, 10178, 10179]
    germany_df = gpd.read_file('./plz-gebiete.shp')
    plot_df = germany_df.query('plz == @postal_codes')

    fig, ax = plt.subplots()
    plot_df.plot(ax=ax)


    and I am adding a basemap using contextily like so:

    ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)


    I tried

    plt.subplots(figsize=(14,11)


    and also

    plot_df.plot(ax=ax, figsize=(14,11))


    These increase the size of the resulting postal code plot, but not my basemap.

    The behavior I would like is a resizing of the basemap, but I can't find any way to do this in the contextily documentation.

    Continue reading...

Compartilhe esta Página