In this video I show:
How to add annotations in python using matplotlib.
How to add arrows to an annotation.
How to add a box to an annotation.
How to save a map in python as an image.
How to format an annotation.
Part 1 - How to make a map in python using basemap: • How to make a map in python using bas...
Part 2 - How to plot latitude and longitude co-ordinates in basemap: • How to plot latitude and longitude co...
matplotlib annotations - https://matplotlib.org/users/annotati...
Jupyter notebook/ Python 3/ Anaconda 3
----------------------------------------------------------------------------------------------------
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_excel(r'C:\Python practise\lat-and-lon.xlsx','Sheet1')
fig = plt.figure(figsize=(12,9))
m = Basemap(projection='mill',
llcrnrlat = -90,
urcrnrlat = 90,
llcrnrlon = -180,
urcrnrlon = 180,
resolution = 'c')
m.drawcoastlines()
m.drawparallels(np.arange(-90,90,10),labels=[True,False,False,False])
m.drawmeridians(np.arange(-180,180,30),labels=[0,0,0,1])
sites_lat_y = df['latitude'].tolist()
sites_lon_x = df['longitude'].tolist()
m.scatter(sites_lon_x,sites_lat_y,latlon=True, s=100, c='blue', marker='o', alpha=1, edgecolor='k', linewidth=1, zorder=2)
bbox_props = dict(fc='white', ec='green', lw=1, boxstyle='round,pad=0.1')
plt.annotate('$\\bf{Aircraft}$\n $\it{measurements}$', m(10,15), xytext=m(-90,0), fontsize=20,
fontname='Arial', color='red', ha='center', va='center',
arrowprops=dict(color='black', width=5, headwidth=20, headlength=20, shrink=0.1),
bbox= bbox_props)
font = {'fontname': 'Comic Sans MS'}
plt.annotate('Samples', m(90,30), xytext=(1.05,0.8), textcoords='axes fraction', fontsize=20, weight=1000, **font,
arrowprops=dict(arrowstyle='-', connectionstyle='angle3'),
bbox = bbox_props)
plt.title('Basemap tutorial', fontsize=20)
plt.show()
fig.savefig('test.png', dpi=1000, bbox_inches='tight')