pythonmatplotlibgeopandas

geopandas.explore - How to plot more than one layer?


I have one dataset with polygons geometry and another with points, I want to plot both in the same graphic with geopandas.explore function but I get the error 'Map' object has no attribute 'set_aspect'

The code is:

import geopandas as gpd
import matplotlib.pyplot as plt

f, ax= plt.subplots(1, figsize=(12,5)) 

Polygons= df.explore('column', scheme='Quantiles', cmap= 'GnBu', k=6)

points= df_points.plot(ax= Polygons)

plt.show()

Solution

  • import geopandas as gpd
    import folium
    
    df = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")).loc[lambda d: d["continent"].eq("Africa")]
    df_points = gpd.read_file(gpd.datasets.get_path("naturalearth_cities"), mask=df)
    
    m = df.explore(height=250, width=500, name="Polygons")
    m = df_points.explore(m=m, color="red", name="Points")
    # this is completely optional
    folium.LayerControl().add_to(m)
    
    m
    

    enter image description here