本文整理汇总了Python中mpl_toolkits.basemap.Basemap.etopo方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.etopo方法的具体用法?Python Basemap.etopo怎么用?Python Basemap.etopo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.etopo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: map3
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def map3():
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap()
m.drawcoastlines()
m.etopo()
plt.show()
示例2: Map_plot_subregion
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def Map_plot_subregion(subregions, ref_dataset, directory):
lons, lats = np.meshgrid(ref_dataset.lons, ref_dataset.lats)
fig = plt.figure()
ax = fig.add_subplot(111)
m = Basemap(
ax=ax,
projection='cyl',
llcrnrlat=lats.min(),
urcrnrlat=lats.max(),
llcrnrlon=lons.min(),
urcrnrlon=lons.max(),
resolution='l')
m.drawcoastlines(linewidth=0.75)
m.drawcountries(linewidth=0.75)
m.etopo()
x, y = m(lons, lats)
#subregion_array = ma.masked_equal(subregion_array, 0)
#max=m.contourf(x, y, subregion_array, alpha=0.7, cmap='Accent')
for subregion in subregions:
draw_screen_poly(subregion[1], m, 'w')
plt.annotate(
subregion[0],
xy=(0.5 * (subregion[1][2] + subregion[1][3]),
0.5 * (subregion[1][0] + subregion[1][1])),
ha='center',
va='center',
fontsize=8)
fig.savefig(directory + 'map_subregion', bbox_inches='tight')
示例3: map2
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def map2():
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap(width=12000000,height=9000000,projection='lcc',
resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.etopo()
plt.show()
示例4: map_plot
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def map_plot():
import matplotlib.pyplot as plt, mpld3
import numpy as np
from mpl_toolkits.basemap import Basemap
fig, ax = plt.subplots()
m = Basemap()
#m = Basemap(projection='ortho',lat_0=0,lon_0=0,resolution='l')
#m = Basemap(projection='moll',lon_0=0,resolution='l')
# Shift 'lon' from [0,360] to [-180,180], make numpy array
#tmp_lon = np.array([lon[n]-360 if l>=180 else lon[n]
# for n,l in enumerate(lon)]) # => [0,180]U[-180,2.5]
#i_east, = np.where(tmp_lon>=0) # indices of east lon
#i_west, = np.where(tmp_lon<0) # indices of west lon
#lon = np.hstack((tmp_lon[i_west], tmp_lon[i_east])) # stack the 2 halves
# Correspondingly, shift the 'air' array
#tmp_air = np.array(air)
#air = np.hstack((tmp_air[:,i_west], tmp_air[:,i_east]))
#poly_paths = m.drawcoastlines().get_paths() # coastline polygon paths
#X,Y = np.meshgrid(lon,lat)
m.etopo()
#m.contourf(X, Y, air, 40, alpha=.75, cmap='jet')
#ticks=range(-90,90,30)
#ax.set_yticks(ticks)
#ax.set_ylabel("Latitude", fontsize=16)
#ax.set_xlabel("Longitude", fontsize=16)
#plt.colorbar()
# D3 Works!
#mpld3.display(fig)
return mpld3.fig_to_html(fig,template_type="general")
示例5: plot_map
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def plot_map(lons, lats, c, legend_label, projection='mill',
llcrnrlat=-80, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180, resolution='i'):
''' Optional Arguments: projection - map projection, default set as 'mill'
llcrnrlat - lower left corner latitude value, default is -80
urcrnrlat - upper right corner latitude value, default is 90
llcrnrlon - lower left corner longitude value, default is -180
urcrnrlon - upper right corner longitude value, default is 180
resolution - the resolution of the plot, default is 'i'
Required Arguments: lons - list of longitude values to be plotted
lats - list of latitude values to be plotted
c - the color of the points to be plotted
legend_label - how this set of points will be labeled on the legend
Returns: m - a basemap object defined by input bounds with input points included '''
# Creates a basic plot of a series of lat,lon points over a defined region
m = Basemap(projection=projection, llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat,
llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, resolution=resolution)
m.drawcoastlines()
m.drawmapboundary()
m.drawcountries()
m.etopo()
m.drawmeridians(np.arange(llcrnrlon, urcrnrlon, 5), labels=[0,0,0,1], fontsize=10)
m.drawparallels(np.arange(llcrnrlat, urcrnrlat, 5), labels=[1,0,0,0], fontsize=10)
x,y = m(lons, lats)
m.scatter(x, y, color=c, label=legend_label, marker='o', edgecolor='none', s=10)
return m
示例6: makeMap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def makeMap(latList, lonList, cityList):
minLon = -130
minLat = 25
maxLon = -60
maxLat = 50
# Below is used to offset a bit the labels of the cities, for projection='merc'.
labelYOffset = -0.9
labelXOffset = 0.8
# Below is used to offset a bit the labels of the cities, for projection='cyl'.
#labelYOffset = -0.4
#labelXOffset = 0.8
plt.figure(1, figsize=(15, 15))
myMap = Basemap(minLon, minLat, maxLon, maxLat, projection='merc', resolution='h')
myMap.drawcoastlines()
# Below if we want to show counties.
#myMap.drawcounties(linewidth=1, linestyle='solid', color='red')
# Below if we want to show states.
#myMap.drawstates(linewidth=2, linestyle='solid', color='green')
myMap.drawcountries(linewidth=3, linestyle='solid', color='black')
myMap.drawrivers(linewidth=1, linestyle='solid', color='blue')
# Another nice option is shaderelief().
#myMap.shadedrelief()
myMap.etopo()
myMap.scatter(latList, lonList, latlon=True, c='red', s=100)
X, Y = myMap(latList, lonList)
# The for loop is to add the text labels of the cities.
for x, y, label in zip(X, Y, cityList):
plt.text(x + labelXOffset, y + labelYOffset, label)
return plt.show()
示例7: show_coord_topo
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def show_coord_topo(windpark, show = True):
"""Plot the topology of a given windpark
Topographic Map with farms
see: http://matplotlib.org/basemap/users/examples.html
Basemap
Parameters
----------
windpark : Windpark
A given windpark to show the topology.
"""
mills = windpark.get_windmills()
target = windpark.get_target()
radius = windpark.get_radius()
#pack latitude and longitude in lists
rel_input_lat = []
rel_input_lon = []
for row in mills:
rel_input_lat.append(np.float64(row.latitude))
rel_input_lon.append(np.float64(row.longitude))
targetcoord = [0.0, 0.0]
targetcoord[0] = np.float64(target.latitude)
targetcoord[1] = np.float64(target.longitude)
graddiff = (radius/111.0) + 0.5 # degree in km
m = Basemap(projection='stere', lon_0=targetcoord[1], lat_0=targetcoord[0],\
llcrnrlon = targetcoord[1]-graddiff, llcrnrlat = targetcoord[0]-graddiff ,\
urcrnrlon = targetcoord[1]+graddiff, urcrnrlat = targetcoord[0]+graddiff ,\
rsphere=6371200., resolution = 'l', area_thresh=1000)
# Target
x_target,y_target = m(targetcoord[1],targetcoord[0])
# Input Farms
rel_inputs_lon, rel_inputs_lat = m(rel_input_lon, rel_input_lat)
# labels = [left,right,top,bottom]
parallels = np.arange(int(targetcoord[0]-3), int(targetcoord[0]+3), 1.)
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(int(targetcoord[1]-3), int(targetcoord[1]+3), 1.)
m.drawmeridians(meridians,labels=[True,False,False,True])
# plot farms in the radius
m.plot(x_target, y_target, 'bo')
m.plot(rel_inputs_lon, rel_inputs_lat, 'r*')
#m.bluemarble()
m.etopo()
m.drawcoastlines()
plt.title("Selected Wind Farms")
if(show):
plt.show()
示例8: BrowseFigures
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def BrowseFigures(self, datadir='', dirPFX='', dirSFX='', datatype='All', depLimit=None, \
llcrnrlon=None, llcrnrlat=None,urcrnrlon=None,urcrnrlat=None, browseflag=True, saveflag=False):
if llcrnrlon==None or llcrnrlat==None or urcrnrlon==None or urcrnrlat==None:
llcrnrlon=self.minlon
llcrnrlat=self.minlat
urcrnrlon=self.maxlon
urcrnrlat=self.maxlat
# print llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat
for geopoint in self.geopoints:
print 'Plotting:'+geopoint.name
if geopoint.depthP.size==0 and geopoint.DispGr.size==0 and geopoint.DispPh.size==0:
continue
plt.close('all')
fig=plb.figure(num=None, figsize=(8, 12), dpi=80, facecolor='w', edgecolor='k')
if datatype=='All':
fig.add_subplot(3,1,1)
else:
fig.add_subplot(2,1,1)
m = Basemap(llcrnrlon=llcrnrlon-1, llcrnrlat=llcrnrlat-1, urcrnrlon=urcrnrlon+1, urcrnrlat=urcrnrlat+1, \
rsphere=(6378137.00,6356752.3142), resolution='l', projection='merc')
lon = geopoint.lon
lat = geopoint.lat
x,y = m(lon, lat)
m.plot(x, y, 'ro', markersize=5)
m.drawcoastlines()
m.etopo()
# m.fillcontinents()
# draw parallels
m.drawparallels(np.arange(-90,90,10),labels=[1,1,0,1])
# draw meridians
m.drawmeridians(np.arange(-180,180,10),labels=[1,1,0,1])
plt.title('Longitude:'+str(geopoint.lon)+' Latitude:'+str(geopoint.lat), fontsize=15)
if datatype=='All':
geopoint.PlotDispBoth(ax=plt.subplot(3,1,2))
# geopoint.PlotDisp(datatype='GrV', ax=plt.subplot(3,1,2))
geopoint.PlotVProfile(ax=plt.subplot(3,1,3), depLimit=depLimit)
elif datatype=='DISP':
# geopoint.PlotDisp(datatype='PhV',ax=plt.subplot(3,1,2))
# geopoint.PlotDisp(datatype='GrV',ax=plt.subplot(3,1,2))
geopoint.PlotDispBoth(ax=plt.subplot(3,1,2))
elif datatype=='VPr':
geopoint.PlotVProfile(depLimit=depLimit,ax=plt.subplot(2,1,2))
else:
raise ValueError('Unknown datatype')
fig.suptitle('Longitude:'+str(geopoint.lon)+' Latitude:'+str(geopoint.lat), fontsize=15)
if browseflag==True:
plt.draw()
plt.pause(1) # <-------
raw_input("<Hit Enter To Close>")
plt.close('all')
if saveflag==True and datadir!='':
fig.savefig(datadir+'/'+dirPFX+geopoint.name+dirSFX+'/'+datatype+'_'+geopoint.name+'.ps', format='ps')
return;
示例9: render_components
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def render_components(C, lats, lons, fname_tmpl = None, ndx = None):
"""
Render the components in C [with dims comp_id x lats x lons] onto
a world map of appropriate size. The method assumes that the lons x lats
generate a rectangle.
"""
m = Basemap(projection='mill',llcrnrlat=min(lats), urcrnrlat=max(lats), llcrnrlon=(min(lons)),
urcrnrlon=max(lons),resolution='c')
if ndx == None:
ndx = np.arange(len(C)) + 1
rmax = np.max(C)
# lattitudes may not be sorted in ascending order, rectify this
lat_ndx = np.argsort(lats)
lats_s = lats[lat_ndx]
# render each topo plot
for ci in range(len(C)):
plt.figure(figsize=(12, 8 * (max(lats) - min(lats)) / 180))
plt.axes([0.05, 0.05, 0.9, 0.85])
m.drawcoastlines()
#m.fillcontinents(color='coral',lake_color='aqua', zorder = 0)
m.etopo(scale = 0.2)
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(0.,361.,60.))
#m.drawmapboundary(fill_color='aqua')
nx = int((m.xmax-m.xmin) / 20000) + 1
ny = int((m.ymax-m.ymin) / 20000) + 1
Ci = C[ci, lat_ndx, :]
f = m.transform_scalar(Ci, lons, lats_s, nx, ny)
# imlim seems to be equivalent to caxis() im MATLAB
imgplt = m.imshow(f, alpha = 0.8)
imgplt.set_clim(-rmax, rmax)
plt.colorbar()
plt.title('Component %d' % (ndx[ci]))
if fname_tmpl:
plt.savefig(fname_tmpl % (ndx[ci]))
if not fname_tmpl:
plt.show()
示例10: testMap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def testMap(X):
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
(x_min,y_min),(x_max,y_max) = findLim(X)
kx,ky = 0.,0.
(x_min,y_min),(x_max,y_max) = (-1.42352-kx,50.930738-ky),(-0.956601+kx,51.086704+ky)
x_mid,y_mid = (x_max-x_min)/2., (y_max-y_min)/2.
m = Basemap(llcrnrlon=x_min,llcrnrlat=y_min,urcrnrlon=x_max,urcrnrlat=y_max,
resolution='i',projection='tmerc',lon_0=x_mid,lat_0=y_min) #adapted from: http://matplotlib.org/basemap/users/tmerc.html
m.drawcoastlines()
#m.bluemarble()
#m.shadedrelief()
m.etopo()
show()
示例11: main
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def main():
ds = nC.Dataset("../../grid_arctic.nc")
data = ds.variables["tas"][:].squeeze()
lon2d_nc = ds.variables["lon"][:]
lat2d_nc = ds.variables["lat"][:]
rplon, rplat = -115.850877297, 21.1216893478
lon_0 = -123.403723307
basemap = Basemap(projection="rotpole", o_lon_p=rplon, o_lat_p=rplat,
lon_0=lon_0 - 180,
llcrnrlon=lon2d_nc[-1, -1], llcrnrlat=lat2d_nc[-1, -1],
urcrnrlon=lon2d_nc[0, 0], urcrnrlat=lat2d_nc[0, 0],
resolution="l")
import matplotlib.pyplot as plt
im = basemap.etopo()
x, y = basemap(lon2d_nc, lat2d_nc)
# basemap.contourf(x, y, data)
# basemap.colorbar()
# basemap.drawcoastlines()
# basemap.drawmeridians(np.arange(-180, 180, 30))
# basemap.drawparallels(np.arange(-90, 90, 40))
plt.show()
pass
示例12: plt_area
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def plt_area(fign):
fig = plt.figure(fign,facecolor='w')
ax = plt.gca()
# Projection + Map properties
m = Basemap(projection='ortho',lat_0=-30,lon_0=-15,resolution='l',ax=ax)
# Meridians and parallels
m.drawmeridians(np.arange(0,360,30))
m.drawparallels(np.arange(-90,90,30))
# Topography
m.etopo()
# Study Area Polygon
rlon = [-70.,-60,-50,-40,-30,-20,-10,0,10,20,
20,20.,20,20,20,20,20,20,20,
10,0,-10,-20,-30,-40,-50,-60,-70,
-70.,-70.,-70,-70,-70,-70,-70,-70,-70]
rlat = [-5.,-5.,-5,-5,-5,-5,-5,-5,-5,-5,
-10,-15,-20,-25,-30,-35,-40,-45,-50.,
-50,-50,-50,-50,-50,-50,-50,-50.,-50,
-45,-40,-35,-30,-25,-20,-15,-10,-5]
rlon,rlat = m(rlon,rlat)
ax.plot(rlon,rlat,color='k',linestyle='dashed',lw=5.)
tkw = dict(fontsize=22,fontweight='demibold')
# Box info
tlon,tlat = m(25,-8)
ax.text(tlon,tlat,ur'5$^{\circ}$S',**tkw)
tlon,tlat = m(25,-53)
ax.text(tlon,tlat,ur'50$^{\circ}$S',**tkw)
tlon,tlat = m(-80,8)
ax.text(tlon,tlat,ur'70$^{\circ}$W',rotation=25,**tkw)
tlon,tlat = m(20,-2)
ax.text(tlon,tlat,ur'20$^{\circ}$E',**tkw)
# plt.draw()
# plt.show(block=False)
return fig
示例13: show_coord_topo_mill
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def show_coord_topo_mill(windmill, show = True):
"""Plot the topology of a windmill
Topographic Map with farms
see: http://matplotlib.org/basemap/users/examples.html
Basemap
Parameters
----------
windmill : Windmill
The given windmill to show the topology.
"""
radius = 20
coord = [0.0, 0.0]
coord[0] = np.float64(windmill.latitude)
coord[1] = np.float64(windmill.longitude)
graddiff = (radius/111.0) + 0.5 # degree in km
m = Basemap(projection='stere', lon_0=coord[1], lat_0=coord[0],\
llcrnrlon = coord[1]-graddiff, llcrnrlat = coord[0]-graddiff ,\
urcrnrlon = coord[1]+graddiff, urcrnrlat = coord[0]+graddiff ,\
rsphere=6371200., resolution = 'l', area_thresh=1000)
# Target
x_mill,y_mill = m(coord[1],coord[0])
# labels = [left,right,top,bottom]
parallels = np.arange(int(coord[0]-3), int(coord[0]+3), 1.)
m.drawparallels(parallels,labels=[False,True,True,False])
meridians = np.arange(int(coord[1]-3), int(coord[1]+3), 1.)
m.drawmeridians(meridians,labels=[True,False,False,True])
# plot farms in the radius
m.plot(x_mill, y_mill, 'bo')
#m.bluemarble()
m.etopo()
m.drawcoastlines()
plt.title("Topography around a Mill")
if(show):
plt.show()
示例14: mapping
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def mapping(self, language, coordinates):
self.path = path.join(path.dirname(__file__), 'geomap.png') #define path for result picture
self.fig = plt.figure(figsize=(18, 4), dpi=150) #basemap figure details
plt.title("Tweets zu #Legion #Warcraft und #WorldofWarcraft") #sets the title for the results
m = Basemap(projection='merc', llcrnrlat=-80, urcrnrlat=80, llcrnrlon=-180,urcrnrlon=180, lat_ts=20, resolution='l') #basemap default settings
m.etopo(scale=0.3) #basemap style
plt.ion()
plt.show()
for elem in coordinates: #marking geo tags on map with language color
self.x, self.y = m(coordinates[elem][0], coordinates[elem][1])
if language[elem] == 'en':
m.plot(self.x, self.y, 'ro', markersize=4) #red for english
elif language[elem] == 'en-gb':
m.plot(self.x, self.y, 'ro', markersize=4) #red for english
elif language[elem] == 'de':
m.plot(self.x, self.y, 'go', markersize=4) #green for german
elif language[elem] == 'fr':
m.plot(self.x, self.y, 'bo', markersize=4) #blue for french
elif language[elem] == 'es':
m.plot(self.x, self.y, 'yo', markersize=4) #yellow for spanish
elif language[elem] == 'ru':
m.plot(self.x, self.y, 'co', markersize=4) #cyan for russian
elif language[elem] == 'it':
m.plot(self.x, self.y, 'mo', markersize=4) #magenta for italian
elif language[elem] == 'und':
m.plot(self.x, self.y, 'wo', markersize=4) #white for undefined
plt.draw()
plt.ioff()
plt.show()
self.fig.savefig(self.path, transparent=True, bbox_inches='tight') #saving result to geomap.png
return
plt.close()
示例15: plot_tweets
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import etopo [as 别名]
def plot_tweets(lat=[0], long=[0], text='', heat=False):
plt.style.use('ggplot')
lon_0 = -125 #further west if negative, further east if not
lon_1 = -66
lat_0 = 25
lat_1 = 52
# create figure and axes instances
plt.clf()
dim = 6
fig = plt.figure(figsize=(dim,(225/494)*dim))
#ax = fig.add_subplot(111)
ax = fig.add_axes([0,0 ,1,1])
# create polar stereographic Basemap instance.
m = Basemap(llcrnrlat=lat_0,urcrnrlat=lat_1, llcrnrlon=lon_0, urcrnrlon=lon_1, resolution='l')
m.drawcoastlines()
m.drawcountries()
if random.random() > 0.5:
m.fillcontinents(color='tan')
elif random.random() > 0.5:
m.bluemarble()
elif random.random() > 0.5:
m.shadedrelief()
elif random.random() > 0.5:
m.etopo()
elif random.random() > 0.5:
m.drawmapboundary(fill_color='aqua')
if heat:
for i, l in enumerate(lat):
lat[i] = lat[i] + random.random()*0.1
long[i] = long[i] + random.random()*0.1
p = ax.plot(long, lat, 'p')
else:
p = ax.plot(long, lat, 'p')
if text is not None:
for i, ht in enumerate(text):
if len(lat) > i:
ax.annotate(ht, (long[i], lat[i]), rotation=random.random()*45.)
plt.savefig('/tmp/twitmap.png')