1+ from __future__ import (absolute_import , division , print_function )
2+
13"""
24Module for plotting data on maps with matplotlib.
35
1315:func:`addcyclic`: Add cyclic (wraparound) point in longitude.
1416"""
1517from distutils .version import LooseVersion
18+
19+ try :
20+ from urllib import urlretrieve
21+ from urllib2 import urlopen
22+ except ImportError :
23+ from urllib .request import urlretrieve , urlopen
24+
1625from matplotlib import __version__ as _matplotlib_version
1726from matplotlib .cbook import is_scalar , dedent
1827# check to make sure matplotlib is not too old.
@@ -4051,7 +4060,6 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
40514060 else :
40524061 newfile = False
40534062 if file .startswith ('http' ):
4054- from urllib import urlretrieve
40554063 self ._bm_file , headers = urlretrieve (file )
40564064 else :
40574065 self ._bm_file = file
@@ -4211,7 +4219,6 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42114219
42124220 returns a matplotlib.image.AxesImage instance.
42134221 """
4214- import urllib2
42154222 if not hasattr (self ,'epsg' ):
42164223 msg = dedent ("""
42174224 Basemap instance must be creating using an EPSG code
@@ -4250,9 +4257,9 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
42504257 f=image" % \
42514258(server ,service ,xmin ,ymin ,xmax ,ymax ,self .epsg ,self .epsg ,xpixels ,ypixels ,dpi )
42524259 # print URL?
4253- if verbose : print basemap_url
4260+ if verbose : print ( basemap_url )
42544261 # return AxesImage instance.
4255- return self .imshow (imread (urllib2 . urlopen (basemap_url )),ax = ax ,
4262+ return self .imshow (imread (urlopen (basemap_url )),ax = ax ,
42564263 origin = 'upper' )
42574264
42584265 def wmsimage (self ,server ,\
@@ -4297,7 +4304,7 @@ def wmsimage(self,server,\
42974304 from owslib .wms import WebMapService
42984305 except ImportError :
42994306 raise ImportError ('OWSLib required to use wmsimage method' )
4300- import urllib2 , io
4307+ import io
43014308 ax = kwargs .pop ('ax' , None ) or self ._check_ax ()
43024309 if not hasattr (self ,'epsg' ):
43034310 msg = dedent ("""
@@ -4325,17 +4332,17 @@ def wmsimage(self,server,\
43254332 # ypixels not given, find by scaling xpixels by the map aspect ratio.
43264333 if ypixels is None :
43274334 ypixels = int (self .aspect * xpixels )
4328- if verbose : print server
4335+ if verbose : print ( server )
43294336 wms = WebMapService (server )
43304337 if verbose :
4331- print 'id: %s, version: %s' % \
4332- (wms .identification .type ,wms .identification .version )
4333- print 'title: %s, abstract: %s' % \
4334- (wms .identification .title ,wms .identification .abstract )
4335- print 'available layers:'
4336- print list (wms .contents )
4337- print 'projection options:'
4338- print wms [kwargs ['layers' ][0 ]].crsOptions
4338+ print ( 'id: %s, version: %s' %
4339+ (wms .identification .type ,wms .identification .version ))
4340+ print ( 'title: %s, abstract: %s' %
4341+ (wms .identification .title ,wms .identification .abstract ))
4342+ print ( 'available layers:' )
4343+ print ( list (wms .contents ) )
4344+ print ( 'projection options:' )
4345+ print ( wms [kwargs ['layers' ][0 ]].crsOptions )
43394346 # remove keys from kwargs that are over-ridden
43404347 for k in ['format' ,'bbox' ,'service' ,'size' ,'srs' ]:
43414348 if 'format' in kwargs : del kwargs ['format' ]
@@ -4346,8 +4353,6 @@ def wmsimage(self,server,\
43464353 # this works for png and jpeg.
43474354 return self .imshow (imread (io .BytesIO (img .read ()),
43484355 format = format ),origin = 'upper' ,alpha = alpha ,ax = ax )
4349- # this works for png, but not jpeg
4350- #return self.imshow(imread(urllib2.urlopen(img.url),format=format),origin='upper')
43514356
43524357 def drawmapscale (self ,lon ,lat ,lon0 ,lat0 ,length ,barstyle = 'simple' ,\
43534358 units = 'km' ,fontsize = 9 ,yoffset = None ,labelstyle = 'simple' ,\
@@ -5095,7 +5100,7 @@ def _addcyclic_lon(a):
50955100 if len (arr ) == 1 :
50965101 return _addcyclic_lon (arr [- 1 ])
50975102 else :
5098- return map (_addcyclic ,arr [:- 1 ]) + [_addcyclic_lon (arr [- 1 ])]
5103+ return list ( map (_addcyclic ,arr [:- 1 ]) + [_addcyclic_lon (arr [- 1 ])])
50995104
51005105def _choosecorners (width ,height ,** kwargs ):
51015106 """
0 commit comments