SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Dave X. <xi...@gm...> - 2011年11月22日 19:51:59
Hi,
I am a new user of matplotlib Basemap. I tried to draw the latitude with
interval 0.1 degree using drawparallels, but failed. I wonder if the
drawparallels can draw latitude lines with small interval instead of
integer values. (drawmeridian can work with small interval 0.1).
Does anyone have any idea to fix this issue?
Thanks!
Dave
#here is a test program to test the drawparallels function
#testbasemap.py
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
import math
latmin=36.803200
latmax=37.306640
lonmin=-76.396026
lonmax=-75.602331
latmin1=math.floor(latmin)
latmax1=math.ceil(latmax)
lonmin1=math.floor(lonmin)
lonmax1=math.ceil(lonmax)
m=Basemap(projection='merc',resolution='h',llcrnrlat=latmin,urcrnrlat=latmax,llcrnrlon=lonmin,urcrnrlon=lonmax)
m.drawcoastlines()
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='coral',lake_color='aqua')
meridians = np.arange(lonmin1,lonmax1,0.1)
m.drawmeridians(meridians,labels=[1,1,0,1],fmt='%5.2f')
parallels=np.arange(latmin,latmax,0.1)
m.drawparallels(parallels,labels=[1,1,0,1],fmt='%5.2f')
plt.savefig('test.png')
#####################################################################
The error message is as follows:
Traceback (most recent call last):
 File "testbasemap.py", line 25, in <module>
 m.drawparallels(parallels,labels=[1,1,0,1],fmt='%5.2f')
 File
"/usr/local/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: 36
From: Jeff W. <js...@fa...> - 2011年11月28日 15:52:20
On 11/22/11 12:51 PM, Dave Xia wrote:
> Hi,
>
> I am a new user of matplotlib Basemap. I tried to draw the latitude 
> with interval 0.1 degree using drawparallels, but failed. I wonder if 
> the drawparallels can draw latitude lines with small interval instead 
> of integer values. (drawmeridian can work with small interval 0.1).
>
> Does anyone have any idea to fix this issue?
>
> Thanks!
>
> Dave
Confirmed. This is now fixed in github master. It's a one-liner, so 
you can manually patch your source if you prefer.
Just change line 2067 in lib/mpl_toolkits/basemap/__init__.py from
if t is not None: linecolls[int(lat)][1].append(t)
to
if t is not None: linecolls[lat][1].append(t)
Regards,
Jeff
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /