import matplotlib.pyplot as plt
from track_functions import draw_basemap

def plotting(data, results_dir):
	"""
	data = [{lats: [...], lons: [...]}, ...]
	"""
	stp_num = len(data)

	print 'plotting %d trajectories...'%stp_num
	
	lon_set = [[]]*stp_num; lat_set = [[]]*stp_num;
	points = {'lats':[],'lons':[]}
	for i in range(stp_num):
		lat_set[i] = data[i]['lats']
		lon_set[i] = data[i]['lons']
		points['lats'].extend(lat_set[i])
		points['lons'].extend(lon_set[i])
	colors = ['magenta','cyan','olive','blue','orange','green','red','yellow','black','purple']
	fig = plt.figure() #figsize=(16,9)
	ax = fig.add_subplot(111)
	plt.suptitle('plotting')
	draw_basemap(ax, points)
	for j in range(stp_num):
		ax.annotate('Start %d'%(j+1), xy=(lon_set[j][0],lat_set[j][0]),xytext=(lon_set[j][0]+0.05,
				lat_set[j][0]+0.03),fontsize=6,arrowprops=dict(arrowstyle="fancy")) #facecolor=colors[i]'''
		ax.plot(lon_set[j],lat_set[j],'o-',color=colors[j%10],markersize=3,label='Start %d'%(j+1)) #markerfacecolor='r',
	plt.savefig(results_dir+'output',dpi=400,bbox_inches='tight')

	print 'plotting done'