[Python] How to make colorbar in geopandas?

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I want to draw topography of South Korea , and I tried to. everything's ok, but it was matter that I don't know how to show colorbar. It is my code and my figureenter image description here Please give me a favor. I appreciate it.

    import geopandas as gpd
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy.feature as cfeature
    from matplotlib.colors import Normalize
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    import rasterio
    from rasterio.plot import show


    path = "D:/파이썬 공부/시각화/행정구역/행정구역_2022.shp"
    gdf = gpd.read_file(path, encoding='utf-8')


    tif_file_path = 'D:/output_NASADEM.tif'
    elevation_data = rasterio.open(tif_file_path)


    fig = plt.figure(figsize=(10, 10))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([125, 131, 32, 40], crs=ccrs.PlateCarree())

    ax.set_xlim([125, 131])
    ax.set_ylim([32, 40])

    ax.add_feature(cfeature.COASTLINE, linewidth=0.8)
    gdf.plot(ax=ax, edgecolor='black', linewidth=1, alpha=0.5, facecolor='none')


    show(elevation_data, ax=ax, cmap='terrain', transform=ccrs.PlateCarree())

    plt.title('Topography')
    plt.show()


    I downloaded geotiff file, asc file of that region by NASADEM,OpenTopography. and using ChatGPT, I wrote and ran that code. the figure that I uploaded is expected but I want to add Colorbar( ex. Lower Station Painted in blue) in that figure. ChatGPT doesn't work well.

    Continue reading...

Compartilhe esta Página