So, I wrote this code that tries to do it but I end up with the map and points being displayed separately

import pandas as pd
import geopandas as gpd
from geopandas import GeoDataFrame
from shapely.geometry import Point
import fiona
import matplotlib.pyplot as plt

def loadPoint():
    df = pd.read_csv(r'C:\Users\imper\Documents\new_GISfiles\earthquakesPH\emscPhilippines2008to2020_lonLat.csv')
    geometry = [Point(xy) for xy in zip(df.Longitude, df.Latitude)]
    crs = {'init': 'epsg:32651'} 
    geo_df = GeoDataFrame(df, crs=crs, geometry=geometry)

    geo_df.to_file(driver='ESRI Shapefile', filename='eqpts.shp')

def plotPoint():
    map = gpd.read_file(r'C:\Users\imper\Documents\new_GISfiles\earthquakesPH\PH_provs.shp')
    map.plot(cmap = 'jet', column = 'NAME_1', figsize=(10,10))

    pt = gpd.read_file(r'C:\Users\imper\Documents\new_GISfiles\earthquakesPH\eqpts.shp')


enter image description here

  • You actually asked for two plot instances; one using map.plot() and the other using pt.plot(). Once an instace is launched, you can reuse it if you assign an axis variable to it. – s.k May 3 at 8:27

The plot() method creates a matplotlib figure and returns an ax object by default. If you want to create just one figure and plot multiple geometries on it, you have to specify the ax parameter. For example:

ax = map.plot(cmap = 'jet', column = 'NAME_1', figsize=(10,10))  # keep ax object in a variable
pt.plot(ax=ax)  # specify ax argument

Make sure, of course, that your layers share the same spatial reference. See the geopandas mapping tools documentation for more details on plotting several layers in the same figure.

On another note, map is a function in Python and its name is reserved. It is convenient to avoid naming your variables after such functions.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.