How to add a title (label) on x and y-axis using python basemap module ?

Published: May 28, 2019

DMCA.com Protection Status

To add labels on x and y-axis while using basemap, a solution is to use the pyplot functions xlabel() and/or ylabel():

plt.xlabel('Longitude', labelpad=40)
plt.ylabel('Latitude', labelpad=40)

Note: the option labelpad allows to adjust the distance between the label and the axis.

How to add a title (label) on x and y-axis using python basemap module ?
How to add a title (label) on x and y-axis using python basemap module ?

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()


m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90, 
                llcrnrlon=-180,urcrnrlon=180,resolution='c')

m.drawcoastlines()
m.fillcontinents()
m.drawparallels(np.arange(-90,90,30),labels=[1,1,0,1], fontsize=8)
m.drawmeridians(np.arange(-180,180,30),labels=[1,1,0,1], rotation=45, fontsize=8)

plt.title('How to add a title on x and y-axis using Basemap ?', fontsize=8)

plt.xlabel('Longitude', labelpad=40, fontsize=8)
plt.ylabel('Latitude', labelpad=40, fontsize=8)

plt.savefig('plot_world_map_using_matplotlib_02.png', bbox_inches='tight')

References

Image

of