1
+ from __future__ import (absolute_import , division , print_function )
2
+
1
3
"""
2
4
Module for plotting data on maps with matplotlib.
3
5
13
15
:func:`addcyclic`: Add cyclic (wraparound) point in longitude.
14
16
"""
15
17
from 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
+
16
25
from matplotlib import __version__ as _matplotlib_version
17
26
from matplotlib .cbook import is_scalar , dedent
18
27
# check to make sure matplotlib is not too old.
@@ -4051,7 +4060,6 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
4051
4060
else :
4052
4061
newfile = False
4053
4062
if file .startswith ('http' ):
4054
- from urllib import urlretrieve
4055
4063
self ._bm_file , headers = urlretrieve (file )
4056
4064
else :
4057
4065
self ._bm_file = file
@@ -4211,7 +4219,6 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4211
4219
4212
4220
returns a matplotlib.image.AxesImage instance.
4213
4221
"""
4214
- import urllib2
4215
4222
if not hasattr (self ,'epsg' ):
4216
4223
msg = dedent ("""
4217
4224
Basemap instance must be creating using an EPSG code
@@ -4250,9 +4257,9 @@ def arcgisimage(self,server='http://server.arcgisonline.com/ArcGIS',\
4250
4257
f=image" % \
4251
4258
(server ,service ,xmin ,ymin ,xmax ,ymax ,self .epsg ,self .epsg ,xpixels ,ypixels ,dpi )
4252
4259
# print URL?
4253
- if verbose : print basemap_url
4260
+ if verbose : print ( basemap_url )
4254
4261
# return AxesImage instance.
4255
- return self .imshow (imread (urllib2 . urlopen (basemap_url )),ax = ax ,
4262
+ return self .imshow (imread (urlopen (basemap_url )),ax = ax ,
4256
4263
origin = 'upper' )
4257
4264
4258
4265
def wmsimage (self ,server ,\
@@ -4297,7 +4304,7 @@ def wmsimage(self,server,\
4297
4304
from owslib .wms import WebMapService
4298
4305
except ImportError :
4299
4306
raise ImportError ('OWSLib required to use wmsimage method' )
4300
- import urllib2 , io
4307
+ import io
4301
4308
ax = kwargs .pop ('ax' , None ) or self ._check_ax ()
4302
4309
if not hasattr (self ,'epsg' ):
4303
4310
msg = dedent ("""
@@ -4325,17 +4332,17 @@ def wmsimage(self,server,\
4325
4332
# ypixels not given, find by scaling xpixels by the map aspect ratio.
4326
4333
if ypixels is None :
4327
4334
ypixels = int (self .aspect * xpixels )
4328
- if verbose : print server
4335
+ if verbose : print ( server )
4329
4336
wms = WebMapService (server )
4330
4337
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 )
4339
4346
# remove keys from kwargs that are over-ridden
4340
4347
for k in ['format' ,'bbox' ,'service' ,'size' ,'srs' ]:
4341
4348
if 'format' in kwargs : del kwargs ['format' ]
@@ -4346,8 +4353,6 @@ def wmsimage(self,server,\
4346
4353
# this works for png and jpeg.
4347
4354
return self .imshow (imread (io .BytesIO (img .read ()),
4348
4355
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')
4351
4356
4352
4357
def drawmapscale (self ,lon ,lat ,lon0 ,lat0 ,length ,barstyle = 'simple' ,\
4353
4358
units = 'km' ,fontsize = 9 ,yoffset = None ,labelstyle = 'simple' ,\
@@ -5095,7 +5100,7 @@ def _addcyclic_lon(a):
5095
5100
if len (arr ) == 1 :
5096
5101
return _addcyclic_lon (arr [- 1 ])
5097
5102
else :
5098
- return map (_addcyclic ,arr [:- 1 ]) + [_addcyclic_lon (arr [- 1 ])]
5103
+ return list ( map (_addcyclic ,arr [:- 1 ]) + [_addcyclic_lon (arr [- 1 ])])
5099
5104
5100
5105
def _choosecorners (width ,height ,** kwargs ):
5101
5106
"""
0 commit comments