Drawing Map with Basemap and Plotting Coordinates

  • Share this:

Code introduction


This function draws a map using the Basemap library and plots a line through specified coordinates.


Technology Stack : Basemap, NumPy

Code Type : Custom function

Code Difficulty : Intermediate


                
                    
def draw_map_with_lsm(arg1, arg2):
    """
    This function draws a map using Basemap library and plots a line of specified coordinates.
    """
    from mpl_toolkits.basemap import Basemap
    import numpy as np
    
    m = Basemap(projection='merc', llcrnrlat=-60, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180, lat_ts=20, resolution='c')
    m.drawcoastlines()
    m.drawcountries()
    m.drawparallels(np.arange(-90., 91., 10.), labels=[1,0,0,0])
    m.drawmeridians(np.arange(-180., 181., 10.), labels=[0,0,0,1])
    
    x, y = m(arg1, arg2)
    m.plot(x, y, marker='o', color='r')
    
    return m                
              
Tags: