plotgeopandaspolylinecolormap

Geopandas - Plot poly-lines with colomap legend


I need to plot poly-lines from a geopandas file, where every line has its own color based on same value (see plot). I am using this script for plotting:

line = geopandas.read_file(shapefile.shp)
ax = plt.subplots()
for i in range(0,3):
      line.loc[[i],'geometry'].plot( ax = ax )

enter image description here

Do you know how to color every line based on its relative value and add a colormap legend on the side?

Thank you!!


Solution

  • I have a column named objekttypn which I want to use as categories:

    import geopandas as gpd
    df = gpd.read_file(r"C:/Users/bera/Desktop/gistest/roads_260.shp")
    
    ax = df.plot(column="objekttypn", cmap="tab20", legend=True, 
    categorical=True, figsize=(10,10))
    

    enter image description here