Using basemap and matplotlib- parallels dont show up
Question: I have a script that plots cruise positions.

The transect plots fine however I get a error message about plotting my
parallels.

Here is the error message :

    
    
    Traceback (most recent call last):
      File "csv_matplot.py", line 37, in <module>
        map.drawparallels(np.arange(47.5, 48.5, 1), labels=[1,0,0,0])
      File "...python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 2067, in drawparallels
        if t is not None: linecolls[int(lat)][1].append(t) 
    KeyError: 47
    

Here is the code :

    
    
    import csv
    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plot
    import numpy as np 
    
    
    #get data from csv
    lat = []
    lon = []
    filename = raw_input("Enter file to map: ")
    with open(filename, 'rU') as f:
        reader = csv.DictReader(f)
        for row in reader:
            lat.append(row['Latitude'])
            lon.append(row['Longitude'])
    
    lats = [float(i) for i in lat]
    lons = [float(i) for i in lon]
    print '.....Making map of %s.....' % filename
    #draw basemap 
    
    map = Basemap(projection='merc',llcrnrlat=47.5,urcrnrlat=48.5,\
                llcrnrlon=-123,urcrnrlon=-122,lat_ts=10,resolution='f')
    map.fillcontinents(color='green',lake_color='aqua')
    map.drawmapboundary(fill_color='blue')
    
    #insert data to basemap
    x,y = map(lons, lats)
    map.plot(x, y, 'r', marker = 'o', linestyle = '-', markersize=4)
    
    map.drawparallels(np.arange(47.5, 48.5, 1), labels=[1,0,0,0])
    map.drawmeridians(np.arange(-123.,-122.,.3),labels=[0,0,0,1])
    
    plot.title(filename)
    plot.show()
    


Answer: Ok so I think it's a problem with your matplotlib install.

First try updating matplotlib to the lastest version if it still does'nt work
try this :

Be careful and make a backup

In :

    
    
    /usr/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py 
    

You must change the line :

    
    
    if t is not None: linecolls[int(lat)][1].append(t)
    

to :

    
    
    if t is not None: linecolls[lat][1].append(t)
    

