[Matplotlib-users] Draw paths on map using matplotlib-basemap
Thank you for your ideas, I leave the correct code to plot trajectories of any object, in my case I have drawn the trajectories of convective storms. 1. # --- Construimos el mapa --- 2. 3. import numpy as np 4. from mpl_toolkits.basemap import Basemap 5. import matplotlib.pyplot as plt 6. from PIL import * 7. fig = plt.figure(figsize=(12,12)) 8. 9. ax = fig.add_axes([0.1,0.1,0.8,0.8]) 10. 11. m = Basemap(projection='cyl', llcrnrlat=12, urcrnrlat=35,llcrnrlon=-120, urcrnrlon=-80, resolution='c', area_thresh=1000.) 12. 13. m.bluemarble() 14. m.drawcoastlines(linewidth=0.5) 15. m.drawcountries(linewidth=0.5) 16. m.drawstates(linewidth=0.5) 17. 18. # --- Dibujamos paralelos y meridianos --- 19. 20. m.drawparallels(np.arange(10.,35.,5.),labels=[1,0,0,1]) 21. m.drawmeridians(np.arange(-120.,-80.,5.),labels=[1,0,0,1]) 22. m.drawmapboundary(fill_color='aqua') 23. 24. # --- Abrimos el archivo que contiene los datos --- 25. 26. import pandas as pd 27. 28. df = pd.read_csv('scm-2004.csv') 29. for evento, group in df.groupby(['evento']): 30. latitude = group.lat.values 31. longitude = group.lon.values 32. x,y = m(longitude, latitude) 33. plt.plot(x,y,'y-',linewidth=2 ) 34. plt.xlabel('Longitud') 35. plt.ylabel('Latitud') 36. plt.title('Trayectorias de Sistemas Convectivos 2004') 37. 38. 39. 40. plt.savefig('track-2004.jpg', dpi=100) With the above code, I get the desired figure. 60 paths drawn on the map of México. I have only one last question: how could indicate the start of each of the storms, someone has an idea how I can do this? -- Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Plot trajectories on an map using matplotlib-basemap
#! /usr/bin/python import numpy as np data = np.loadtxt('path-tracks.csv',dtype=np.str,delimiter=',',skiprows=1) print data [['19.70' '-95.20' '2/5/04 6:45 AM' '1' '-38' 'CCM'] ['19.70' '-94.70' '2/5/04 7:45 AM' '1' '-48' 'CCM'] ['19.30' '-93.90' '2/5/04 8:45 AM' '1' '-60' 'CCM'] ['19.00' '-93.50' '2/5/04 9:45 AM' '1' '-58' 'CCM'] ['19.00' '-92.80' '2/5/04 10:45 AM' '1' '-50' 'CCM'] ['19.20' '-92.60' '2/5/04 11:45 AM' '1' '-40' 'CCM'] ['19.90' '-93.00' '2/5/04 12:45 PM' '1' '-43' 'CCM'] ['20.00' '-92.80' '2/5/04 1:15 PM' '1' '-32' 'CCM'] ['23.10' '-100.20' '30/5/04 4:45 AM' '2' '-45' 'SCME'] ['23.20' '-100.00' '30/5/04 5:45 AM' '2' '-56' 'SCME'] ['23.30' '-100.00' '30/5/04 6:45 AM' '2' '-48' 'SCME'] ['23.30' '-100.20' '30/5/04 7:45 AM' '2' '-32' 'SCME'] ['23.40' '-99.00' '31/5/04 3:15 AM' '3' '-36' 'SCM'] ['23.50' '-98.90' '31/5/04 4:15 AM' '3' '-46' 'SCM'] ['23.60' '-98.70' '31/5/04 5:15 AM' '3' '-68' 'SCM'] ['23.70' '-98.80' '31/5/04 6:15 AM' '3' '-30' 'SCM']] with the above code I get an array whose columns represent: [Lat, Lon, Date, Identifier, Temperatures, Category]. Now, I will put a code that allows me to plot the first and second column on the map of Mexico: #!/usr/bin/python #Project Storm: Plot trajectories of convective systems #import libraries import numpy as np from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as pl # Plot a map for Mexico m = Basemap(projection='cyl', llcrnrlat=12, urcrnrlat=35,llcrnrlon=-120, urcrnrlon=-80, resolution='c', area_thresh=1000.) m.bluemarble() m.drawcoastlines(linewidth=0.5) m.drawcountries(linewidth=0.5) m.drawstates(linewidth=0.5) #Draw parallels and meridians m.drawparallels(np.arange(10.,35.,5.)) m.drawmeridians(np.arange(-120.,-80.,10.)) m.drawmapboundary(fill_color='aqua') #Open file whit numpy data = np.loadtxt('path-tracks.csv', dtype=np.str,delimiter=' , ', skiprows=1) latitude = data[:,0] longitude = data[:,1] #Convert latitude and longitude to coordinates X and Y x, y = m(longitude, latitude) #Plot the points on the map pl.plot(x,y,'ro-') pl.show() The points plotted on the map, corresponding to three different paths with a line connecting all points. Mi final idea is to draw a line connecting the points associated with each path, How I can do this? or How should I structure my data to plot the different paths? is posible draw an identifier or a mark for each path? how I can set the size of the figure so that it can distinguish the separation between the points? -- Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnnow-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Plot trajectories on basemap
#! /usr/bin/python import numpy as np data = np.loadtxt('path-tracks.csv',dtype=np.str,delimiter=',',skiprows=1) print data [['19.70' '-95.20' '2/5/04 6:45 AM' '1' '-38' 'CCM'] ['19.70' '-94.70' '2/5/04 7:45 AM' '1' '-48' 'CCM'] ['19.30' '-93.90' '2/5/04 8:45 AM' '1' '-60' 'CCM'] ['19.00' '-93.50' '2/5/04 9:45 AM' '1' '-58' 'CCM'] ['19.00' '-92.80' '2/5/04 10:45 AM' '1' '-50' 'CCM'] ['19.20' '-92.60' '2/5/04 11:45 AM' '1' '-40' 'CCM'] ['19.90' '-93.00' '2/5/04 12:45 PM' '1' '-43' 'CCM'] ['20.00' '-92.80' '2/5/04 1:15 PM' '1' '-32' 'CCM'] ['23.10' '-100.20' '30/5/04 4:45 AM' '2' '-45' 'SCME'] ['23.20' '-100.00' '30/5/04 5:45 AM' '2' '-56' 'SCME'] ['23.30' '-100.00' '30/5/04 6:45 AM' '2' '-48' 'SCME'] ['23.30' '-100.20' '30/5/04 7:45 AM' '2' '-32' 'SCME'] ['23.40' '-99.00' '31/5/04 3:15 AM' '3' '-36' 'SCM'] ['23.50' '-98.90' '31/5/04 4:15 AM' '3' '-46' 'SCM'] ['23.60' '-98.70' '31/5/04 5:15 AM' '3' '-68' 'SCM'] ['23.70' '-98.80' '31/5/04 6:15 AM' '3' '-30' 'SCM']] with the above code I get an array whose columns represent: [Lat, Lon, Date, Identifier, Temperatures, Category]. Now, I will put a code that allows me to plot the first and second column on the map of Mexico: #!/usr/bin/python #Project Storm: Plot trajectories of convective systems #import libraries import numpy as np from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as pl # Plot a map for Mexico m = Basemap(projection='cyl', llcrnrlat=12, urcrnrlat=35,llcrnrlon=-120, urcrnrlon=-80, resolution='c', area_thresh=1000.) m.bluemarble() m.drawcoastlines(linewidth=0.5) m.drawcountries(linewidth=0.5) m.drawstates(linewidth=0.5) #Draw parallels and meridians m.drawparallels(np.arange(10.,35.,5.)) m.drawmeridians(np.arange(-120.,-80.,10.)) m.drawmapboundary(fill_color='aqua') #Open file whit numpy data = np.loadtxt('path-tracks.csv', dtype=np.str,delimiter=' , ', skiprows=1) latitude = data[:,0] longitude = data[:,1] #Convert latitude and longitude to coordinates X and Y x, y = m(longitude, latitude) #Plot the points on the map pl.plot(x,y,'ro-') pl.show() with this I get the figure in attachment The points plotted on the map, corresponding to three different paths. Mi final idea is to draw a line connecting the points associated with each path, How I can do this? is posible draw an identifier or a mark for each path? how I can set the size of the figure so that it can distinguish the separation between the points? -- Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnnow-d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users