You can download this code by clicking the button below.
This code is now available for download.
This function uses the Basemap library to create a map based on longitude and latitude, and draws coastlines, country boundaries, and meridians.
Technology Stack : Basemap, Matplotlib
Code Type : Map drawing
Code Difficulty : Intermediate
def create_random_map(x_range, y_range):
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# Create a Basemap instance
m = Basemap(projection='merc', llcrnrlat=y_range[0], urcrnrlat=y_range[1],
llcrnrlon=x_range[0], urcrnrlon=x_range[1], lat_ts=20, resolution='c')
# Draw coastlines, countries, and meridians
m.drawcoastlines()
m.drawcountries()
m.drawmeridians(np.arange(-180, 180, 30), labels=[1, 0, 0, 0])
# Draw parallels
m.drawparallels(np.arange(-90., 91., 10.), labels=[0, 0, 0, 1])
# Create a plot
plt.show()