Build multiple lines in python / basemap

I just started learning python / matplotlib / baseemap and really could use some help. How do you build multiple lines?

Say my data looks something like this:

[(lat1,lon1) (lat2,lon2) (lat3,lon3)] [(lat1,lon1) (lat2,lon2) (lat3,lon3)] [(lat1,lon1) (lat2,lon2) (lat3,lon3)] ... 

I want to build a separate row for each row in my data. However, I get with my code what connects the last point in the previous line to the first in the current line. Can someone help me fix this? Thanks!

EDIT: Here is what I have for the code:

 for page in files: file = open(dir + '/' + page) for line in file: lines = line.split() time = lines[0] lon = lines[1] lat = lines[2] lon_float = float(lon) lat_float = float(lat) lats.append(lat_float) lons.append(lon_float) x,y = m(lons, lats) m.plot(x,y,'D-') plt.show() 

I want to build one line for each file (which has several lat / long pairs). Also m is my Baseplot instance

+4
source share
1 answer

You do not clear lats and lons , so every time through the file loop you accumulate points.

 for page in files: file = open(dir + '/' + page) lats = [] lons = [] for line in file: ... 

EDIT: Answer Completely Rewritten

+2
source

All Articles