matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
772 stars 390 forks source link

drawparallels crashes under certain map conditions #37

Closed mhearne-usgs closed 12 years ago

mhearne-usgs commented 12 years ago

The script below runs just fine with basemap version 1.0.1, but crashes with the following error on version 1.0.2.: Traceback (most recent call last): File "./maptest.py", line 33, in linewidth=1,color='black',yoffset=yoff,xoffset=xoff,dashes=[1,0]) File "/Library/Frameworks/Python.framework/Versions/7.2/lib/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: 38

This script is a trivialized snippet of a real function, where the meridian and parallel values are dynamically derived. The instance that crashed generated the values below.

Script:

!/usr/bin/env python

import matplotlib

use the non-interactive matplotlib setting

matplotlib.use('agg') from mpl_toolkits.basemap import Basemap from pylab import *

figheight = 5.35891 figwidth = 5.4 bounds = [-89.704166666702776, -85.962500000037608, 36.987499999949222, 39.895833333281395] clat = bounds[2] + (bounds[3] - bounds[2])/2 clon = bounds[0] + (bounds[1] - bounds[0])/2 fig = figure(figsize=(figwidth,figheight),edgecolor='g',facecolor='g') ax1 = fig.add_axes([0,0,1.0,1.0]) mapcontour = Basemap(llcrnrlon=bounds[0],llcrnrlat=bounds[2], urcrnrlon=bounds[1],urcrnrlat=bounds[3], resolution='h',projection='merc',lat_ts=clat)

par = array([ 37. , 37.75, 38.5 , 39.25]) mer = array([-89.5, -88.5, -87.5, -86.5]) xmap_range = mapcontour.xmax-mapcontour.xmin ymaprange = mapcontour.ymax-mapcontour.ymin xoff = -0.09(xmaprange) yoff = -0.04(ymap_range) mapcontour.drawmeridians(mer,labels=[0,0,1,0],fontsize=8, linewidth=1,color='black',yoffset=yoff,xoffset=xoff,dashes=[1,0]) mapcontour.drawparallels(par,labels=[0,1,0,0],fontsize=8, linewidth=1,color='black',yoffset=yoff,xoffset=xoff,dashes=[1,0]) mapcontour.drawmapboundary(color='k',linewidth=2.0) savefig('test.png')

jswhit commented 12 years ago

This is fixed in git master.