Search code examples
pythonmatplotlibshapefilegeopandas

Plot shapefiles with geometry point and line on a single plot in python


I have 3 shapefiles that I want to layer/ superimpose on top of each other, so all the plots can be viewed on a single map. I have bus stops, bus routes, and a zone map in each of the shapefiles. When attempting to plot the route on the zone, the plot is easily achieved using the code below.

fig, ax = plt.subplots(figsize = (20,20))

ZoneMap.plot(ax=ax, alpha = 0.2, color = 'blue')
ExistingRoutesMap.plot(ax=ax,color = 'green', label = 'bus routes')

plt.show()

enter image description here

When I try to map the bus stops on top of the zone and the route, the map gets skewed, and all points are piled up in a corner of a map because it looks like the scales are off.

fig, ax = plt.subplots(figsize = (20,20))

ZoneMap.plot(ax=ax, alpha = 0.2, color = 'blue')
ExistingRoutesMap.plot(ax=ax,color = 'green', label = 'bus routes')
BJCTABusStops.plot(ax=ax, color = 'orange', label = 'bus stops')

plt.show()

enter image description here

If I plot the stops alone, without the zone and route layers, I see the below plot, which follows the exact shape of the routes:

enter image description here

How can I correct this issue and have all the maps show together on top of each other?


Solution

  • Here is the code that I used

    BJCTABusStops = gpd.read_file(r'Bus_Stops-shp\Bus_Stops.shp')
    ExistingRoutesMap = gpd.read_file(r'Birmingham_Area_Transit_Routes-shp\Birmingham_Area_Transit_Routes.shp')
    ZoneMap = gpd.read_file(r'Zoning_Map_for_Jefferson_County%2C_AL\Zoning_Map_for_Jefferson_County%2C_AL.shp')
    
    fig, ax = plt.subplots(figsize = (20,20))
    ZoneMap.plot(ax=ax, alpha = 0.2, color = 'blue')
    ExistingRoutesMap.plot(ax=ax,color = 'green', label = 'bus routes')
    BJCTABusStops.plot(ax=ax, color = 'orange', label = 'bus stops')
    plt.show()
    

    Produce this map for me

    enter image description here

    Did you correctly upload the data and sure that you haven't modified ?