%pylab inline
plt.rcParams['figure.figsize'] = (10.0, 6.0)
Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['Polygon', 'poly', 'sign', 'flatten', 'conjugate', 'diff', 'Circle', 'tan', 'roots', 'plot', 'eye', 'trace', 'floor', 'diag', 'invert', 'nan', 'sqrt', 'source', 'add', 'zeros', 'take', 'var', 'prod', 'plotting', 'product', 'exp', 'power', 'multinomial', 'transpose', 'test', 'beta', 'ones', 'sinh', 'vectorize', 'cosh', 'log', 'cos', 'seterr', 'f', 'tanh', 'det', 'pi', 'sin', 'binomial', 'solve', 'mod', 'reshape', 'trunc', 'gamma', 'interactive'] `%matplotlib` prevents importing * from pylab and numpy
import mpl_toolkits.basemap as bm
from matplotlib.mlab import csv2rec
import sys
print sys.version
print 'numpy= ' + np.__version__
print 'matplotlib= ' + mpl.__version__
print 'basemap= ' + bm.__version__
2.7.6 | 64-bit | (default, Jan 29 2014, 17:09:48) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] numpy= 1.8.0 matplotlib= 1.3.1 basemap= 1.0.7
# active world volcano spreadshethttp://www.volcano.si.edu/list_volcano_excel.cfm
gvp = csv2rec('GVP_Volcano_List.csv',skiprows=1)
print gvp.size, gvp.longitude, gvp.latitude
1550 [ 6.85 2.97 2.53 ..., -28.14 -27.57 -28.246] [ 50.17 45.775 42.17 ..., -56.656 -56.3 -56.014]
# Error plotting lots of unsorted longitudes and latitudes
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', ax=ax1)
bmap.drawcoastlines()
bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=True) # causes error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-5-7659135a48fc> in <module>() 3 bmap = bm.Basemap(projection='cyl',resolution='c', ax=ax1) 4 bmap.drawcoastlines() ----> 5 bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=True) # causes error: /Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in with_transform(self, x, y, *args, **kwargs) 538 if self.projection in _cylproj or self.projection in _pseudocyl: 539 if x.ndim == 1: --> 540 x = self.shiftdata(x) 541 elif x.ndim == 0: 542 if x > 180: /Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in shiftdata(self, lonsin, datain, lon_0) 4910 itemindex = len(lonsin)-np.where(londiff>=thresh)[0] 4911 #if itemindex.any(): -SH, avoids error? -> 4912 if itemindex: 4913 # check to see if cyclic (wraparound) point included 4914 # if so, remove it. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
# No error with latlon=False?
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', ax=ax1)
bmap.drawcoastlines()
bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=False)
[<matplotlib.lines.Line2D at 0x10cfe4b10>]
# Only half points plotted with shifted center of map
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', lon_0=180, ax=ax1)
bmap.drawcoastlines()
bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=False)
[<matplotlib.lines.Line2D at 0x10d2d2cd0>]
# Other half for negative 180
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', lon_0=-180, ax=ax1)
bmap.drawcoastlines()
bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=False)
[<matplotlib.lines.Line2D at 0x10cfd1890>]
# Error again in shiftdata
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', lon_0=180, ax=ax1)
bmap.drawcoastlines()
bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=True)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-9-4083a0a948c8> in <module>() 3 bmap = bm.Basemap(projection='cyl',resolution='c', lon_0=180, ax=ax1) 4 bmap.drawcoastlines() ----> 5 bmap.plot(gvp.longitude, gvp.latitude, 'r^', ms=4, latlon=True) /Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in with_transform(self, x, y, *args, **kwargs) 538 if self.projection in _cylproj or self.projection in _pseudocyl: 539 if x.ndim == 1: --> 540 x = self.shiftdata(x) 541 elif x.ndim == 0: 542 if x > 180: /Users/scott/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.pyc in shiftdata(self, lonsin, datain, lon_0) 4910 itemindex = len(lonsin)-np.where(londiff>=thresh)[0] 4911 #if itemindex.any(): -SH, avoids error? -> 4912 if itemindex: 4913 # check to see if cyclic (wraparound) point included 4914 # if so, remove it. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
# pre-sort longitude and latitude? - no error, but not plotted correctly.
lons = gvp.longitude
lats = gvp.latitude
asc = lons.argsort() #ascending -180 to 180
lons_asc = lons[asc] #lons[asc][::-1] #descending
lats_asc = lats[asc]
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='cyl',resolution='c', lon_0=-180.0, ax=ax1)
bmap.drawcoastlines()
bmap.plot(lons_asc,lats_asc, 'r^', ms=4, latlon=True)
[<matplotlib.lines.Line2D at 0x10cc79b10>]
# Explicitly transform coords in projected coordinates works fine.
fig,ax1 = plt.subplots()
bmap = bm.Basemap(projection='kav7',resolution='c', lon_0=180.0, ax=ax1)
bmap.drawcoastlines()
x,y = bmap(gvp.longitude,gvp.latitude)
bmap.plot(x,y,'r^', ms=4, latlon=False)
[<matplotlib.lines.Line2D at 0x10cfe7c10>]