Skip to content

Commit 151de35

Browse files
committed
Merge branch 'issue-unicode-literals' into develop
2 parents cba0ebc + c2d4174 commit 151de35

File tree

2 files changed

+71
-59
lines changed

2 files changed

+71
-59
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ https://semver.org/spec/v2.0.0.html
7878
(solves issue [#594], thanks to @qianwu2 and @rcomer).
7979

8080
### Removed
81+
- Use of unicode literals within the library.
8182
- Attribute `__version__` in `mpl_toolkits.basemap.proj` module.
8283
- Module `mpl_toolkits.basemap.test`, whose content is migrated to the
8384
test suite in the `test` folder.

packages/basemap/src/mpl_toolkits/basemap/__init__.py

+70-59
Original file line numberDiff line numberDiff line change
@@ -4528,20 +4528,21 @@ def drawmapscale(self,lon,lat,lon0,lat0,length,barstyle='simple',\
45284528
xc,yc = self(lon,lat)
45294529
# make sure lon_0 between -180 and 180
45304530
lon_0 = ((lon0+360) % 360) - 360
4531+
degchar = b"\xc2\xb0".decode("utf-8")
45314532
if lat0>0:
45324533
if lon>0:
4533-
lonlatstr = u'%g\N{DEGREE SIGN}N, %g\N{DEGREE SIGN}E' % (lat0,lon_0)
4534+
lonlatstr = '%g%sN, %g%sE' % (lat0, degchar, lon_0, degchar)
45344535
elif lon<0:
4535-
lonlatstr = u'%g\N{DEGREE SIGN}N, %g\N{DEGREE SIGN}W' % (lat0,lon_0)
4536+
lonlatstr = '%g%sN, %g%sW' % (lat0, degchar, lon_0, degchar)
45364537
else:
4537-
lonlatstr = u'%g\N{DEGREE SIGN}, %g\N{DEGREE SIGN}W' % (lat0,lon_0)
4538+
lonlatstr = '%g%s, %g%sW' % (lat0, degchar, lon_0, degchar)
45384539
else:
45394540
if lon>0:
4540-
lonlatstr = u'%g\N{DEGREE SIGN}S, %g\N{DEGREE SIGN}E' % (lat0,lon_0)
4541+
lonlatstr = '%g%sS, %g%sE' % (lat0, degchar, lon_0, degchar)
45414542
elif lon<0:
4542-
lonlatstr = u'%g\N{DEGREE SIGN}S, %g\N{DEGREE SIGN}W' % (lat0,lon_0)
4543+
lonlatstr = '%g%sS, %g%sW' % (lat0, degchar, lon_0, degchar)
45434544
else:
4544-
lonlatstr = u'%g\N{DEGREE SIGN}S, %g\N{DEGREE SIGN}' % (lat0,lon_0)
4545+
lonlatstr = '%g%sS, %g%s' % (lat0, degchar, lon_0, degchar)
45454546
# left edge of scale
45464547
lon1,lat1 = self(x0-length/2,y0,inverse=True)
45474548
x1,y1 = self(lon1,lat1)
@@ -5316,76 +5317,86 @@ def __delitem__(self,key):
53165317
self[key].remove()
53175318
super(_dict, self).__delitem__(key)
53185319

5319-
def _setlonlab(fmt,lon,labelstyle):
5320-
# set lon label string (called by Basemap.drawmeridians)
5321-
try: # fmt is a function that returns a formatted string
5320+
5321+
def _setlonlab(fmt, lon, labelstyle):
5322+
"""Set longitude label string (called by :meth:`Basemap.drawmeridians`)."""
5323+
5324+
try:
5325+
# `fmt` is a function that returns a formatted string.
53225326
lonlab = fmt(lon)
5323-
except: # fmt is a format string.
5324-
if lon>180:
5325-
if mpl.rcParams['text.usetex']:
5326-
if labelstyle=='+/-':
5327-
lonlabstr = r'${\/-%s\/^{\circ}}$'%fmt
5327+
except:
5328+
# `fmt` is a format string.
5329+
degchar = b"\xc2\xb0".decode("utf-8")
5330+
if lon > 180:
5331+
if mpl.rcParams["text.usetex"]:
5332+
if labelstyle == "+/-":
5333+
lonlabstr = r"${\/-%s\/^{\circ}}$" % fmt
53285334
else:
5329-
lonlabstr = r'${%s\/^{\circ}\/W}$'%fmt
5335+
lonlabstr = r"${%s\/^{\circ}\/W}$" % fmt
53305336
else:
5331-
if labelstyle=='+/-':
5332-
lonlabstr = u'-%s\N{DEGREE SIGN}'%fmt
5337+
if labelstyle == "+/-":
5338+
lonlabstr = r"-%s%s" % (fmt, degchar)
53335339
else:
5334-
lonlabstr = u'%s\N{DEGREE SIGN}W'%fmt
5335-
lonlab = lonlabstr%np.fabs(lon-360)
5336-
elif lon<180 and lon != 0:
5337-
if mpl.rcParams['text.usetex']:
5338-
if labelstyle=='+/-':
5339-
lonlabstr = r'${\/+%s\/^{\circ}}$'%fmt
5340+
lonlabstr = r"%s%sW" % (fmt, degchar)
5341+
lonlab = lonlabstr % np.fabs(lon - 360)
5342+
elif lon < 180 and lon != 0:
5343+
if mpl.rcParams["text.usetex"]:
5344+
if labelstyle == "+/-":
5345+
lonlabstr = r"${\/+%s\/^{\circ}}$" % fmt
53405346
else:
5341-
lonlabstr = r'${%s\/^{\circ}\/E}$'%fmt
5347+
lonlabstr = r"${%s\/^{\circ}\/E}$" % fmt
53425348
else:
5343-
if labelstyle=='+/-':
5344-
lonlabstr = u'+%s\N{DEGREE SIGN}'%fmt
5349+
if labelstyle == "+/-":
5350+
lonlabstr = r"+%s%s" % (fmt, degchar)
53455351
else:
5346-
lonlabstr = u'%s\N{DEGREE SIGN}E'%fmt
5347-
lonlab = lonlabstr%lon
5352+
lonlabstr = r"%s%sE" % (fmt, degchar)
5353+
lonlab = lonlabstr % lon
53485354
else:
5349-
if mpl.rcParams['text.usetex']:
5350-
lonlabstr = r'${%s\/^{\circ}}$'%fmt
5355+
if mpl.rcParams["text.usetex"]:
5356+
lonlabstr = r"${%s\/^{\circ}}$" % fmt
53515357
else:
5352-
lonlabstr = u'%s\N{DEGREE SIGN}'%fmt
5353-
lonlab = lonlabstr%lon
5358+
lonlabstr = r"%s%s" % (fmt, degchar)
5359+
lonlab = lonlabstr % lon
53545360
return lonlab
53555361

5356-
def _setlatlab(fmt,lat,labelstyle):
5357-
# set lat label string (called by Basemap.drawparallels)
5358-
try: # fmt is a function that returns a formatted string
5359-
latlab = fmt(lat)
5360-
except: # fmt is a format string.
5361-
if lat<0:
5362-
if mpl.rcParams['text.usetex']:
5363-
if labelstyle=='+/-':
5364-
latlabstr = r'${\/-%s\/^{\circ}}$'%fmt
5362+
5363+
def _setlatlab(fmt, lat, labelstyle):
5364+
"""Set latitude label string (called by :meth:`Basemap.drawparallels`)."""
5365+
5366+
try:
5367+
# `fmt` is a function that returns a formatted string.
5368+
latlab = fmt(lat)
5369+
except:
5370+
# `fmt` is a format string.
5371+
degchar = b"\xc2\xb0".decode("utf-8")
5372+
if lat < 0:
5373+
if mpl.rcParams["text.usetex"]:
5374+
if labelstyle == "+/-":
5375+
latlabstr = r"${\/-%s\/^{\circ}}$" % fmt
53655376
else:
5366-
latlabstr = r'${%s\/^{\circ}\/S}$'%fmt
5377+
latlabstr = r"${%s\/^{\circ}\/S}$" % fmt
53675378
else:
5368-
if labelstyle=='+/-':
5369-
latlabstr = u'-%s\N{DEGREE SIGN}'%fmt
5379+
if labelstyle == "+/-":
5380+
latlabstr = r"-%s%s" % (fmt, degchar)
53705381
else:
5371-
latlabstr = u'%s\N{DEGREE SIGN}S'%fmt
5372-
latlab = latlabstr%np.fabs(lat)
5373-
elif lat>0:
5374-
if mpl.rcParams['text.usetex']:
5375-
if labelstyle=='+/-':
5376-
latlabstr = r'${\/+%s\/^{\circ}}$'%fmt
5382+
latlabstr = r"%s%sS" % (fmt, degchar)
5383+
latlab = latlabstr % np.fabs(lat)
5384+
elif lat > 0:
5385+
if mpl.rcParams["text.usetex"]:
5386+
if labelstyle == "+/-":
5387+
latlabstr = r"${\/+%s\/^{\circ}}$" % fmt
53775388
else:
5378-
latlabstr = r'${%s\/^{\circ}\/N}$'%fmt
5389+
latlabstr = r"${%s\/^{\circ}\/N}$" % fmt
53795390
else:
5380-
if labelstyle=='+/-':
5381-
latlabstr = u'+%s\N{DEGREE SIGN}'%fmt
5391+
if labelstyle == "+/-":
5392+
latlabstr = r"+%s%s" % (fmt, degchar)
53825393
else:
5383-
latlabstr = u'%s\N{DEGREE SIGN}N'%fmt
5384-
latlab = latlabstr%lat
5394+
latlabstr = r"%s%sN" % (fmt, degchar)
5395+
latlab = latlabstr % lat
53855396
else:
5386-
if mpl.rcParams['text.usetex']:
5387-
latlabstr = r'${%s\/^{\circ}}$'%fmt
5397+
if mpl.rcParams["text.usetex"]:
5398+
latlabstr = r"${%s\/^{\circ}}$" % fmt
53885399
else:
5389-
latlabstr = u'%s\N{DEGREE SIGN}'%fmt
5390-
latlab = latlabstr%lat
5400+
latlabstr = r"%s%s" % (fmt, degchar)
5401+
latlab = latlabstr % lat
53915402
return latlab

0 commit comments

Comments
 (0)