本文整理汇总了Python中mpl_toolkits.basemap.Basemap方法的典型用法代码示例。如果您正苦于以下问题:Python basemap.Basemap方法的具体用法?Python basemap.Basemap怎么用?Python basemap.Basemap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap
的用法示例。
在下文中一共展示了basemap.Basemap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initBasemap
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def initBasemap(self):
# NOTE: http://matplotlib.org/basemap/api/basemap_api.html
# NOTE: https://gist.github.com/dannguyen/eb1c4e70565d8cb82d63
self.mapAxes.clear()
basemap_kwargs = {}
basemap_kwargs.update(self.DEFAULT_BASEMAP_KWARGS)
basemap_kwargs.update(
ax=self.mapAxes
)
self.basemap = Basemap(**basemap_kwargs)
self.basemap.bluemarble(scale=0.25, alpha=0.42)
self.basemap.drawcoastlines(color='#555566', linewidth=1)
self.basemap.drawmeridians(np.arange(0, 360, 30))
self.basemap.drawparallels(np.arange(-90, 90, 30))
self.canvas.draw_idle()
示例2: generate_map
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def generate_map(output, lats=[], lons=[], wesn=None):
"""
Using Basemap and the matplotlib toolkit, this function generates a map and
puts a red dot at the location of every IP addresses found in the list.
The map is then saved in the file specified in `output`.
"""
print("Generating map and saving it to {}".format(output))
if wesn:
wesn = [float(i) for i in wesn.split('/')]
m = Basemap(projection='cyl', resolution='l',
llcrnrlon=wesn[0], llcrnrlat=wesn[2],
urcrnrlon=wesn[1], urcrnrlat=wesn[3])
else:
m = Basemap(projection='cyl', resolution='l')
m.bluemarble()
x, y = m(lons, lats)
m.scatter(x, y, s=1, color='#ff0000', marker='o', alpha=0.3)
plt.savefig(output, dpi=300, bbox_inches='tight')
示例3: main2
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def main2():
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# resolution = 'i' means use intermediate resolution coastlines.
# lon_0, lat_0 are the central longitude and latitude of the projection.
m = Basemap(llcrnrlon=9.5, llcrnrlat=63.2,
urcrnrlon=10.9, urcrnrlat=64.,
resolution='i', projection='tmerc',
lon_0=10.7, lat_0=63.4)
# can get the identical map this way (by specifying width and
# height instead of lat/lon corners)
# m = Basemap(width=894887,height=1116766,\
# resolution='i',projection='tmerc',lon_0=-4.36,lat_0=54.7)
m.drawcoastlines()
m.fillcontinents(color='coral', lake_color='aqua')
# m.drawparallels(np.arange(-40, 61., 2.))
# m.drawmeridians(np.arange(-20., 21., 2.))
m.drawmapboundary(fill_color='aqua')
plt.title("Transverse Mercator Projection")
plt.show()
示例4: plot_route
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def plot_route(individual):
m = Basemap(projection='lcc', resolution=None,
width=5E6, height=5E6,
lat_0=-15, lon_0=-56)
plt.axis('off')
plt.title("Shortest Route")
for i in range(0, len(individual.genes)):
x, y = m(individual.genes[i].lng, individual.genes[i].lat)
plt.plot(x, y, 'ok', c='r', markersize=5)
if i == len(individual.genes) - 1:
x2, y2 = m(individual.genes[0].lng, individual.genes[0].lat)
else:
x2, y2 = m(individual.genes[i+1].lng, individual.genes[i+1].lat)
plt.plot([x, x2], [y, y2], 'k-', c='r')
示例5: plot
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def plot(self, variable, time, level, **plot_basemap_kwargs):
"""
Wrapper to plot a specified field from an CFSReanalysis object.
:param variable: str: variable to retrieve
:param time: datetime: requested time
:param level: int: requested pressure level
:param plot_basemap_kwargs: kwargs passed to the plot.plot_functions.plot_basemap function (see the doc for
plot_basemap for more information on options for Basemap plot)
:return: matplotlib Figure object
"""
from ..plot import plot_basemap
print('CFSReanalysis.plot: plot of %s at %d mb (%s)' % (variable, level, time))
field = self.field(variable, time, level)
fig = plot_basemap(self.basemap, self.lon, self.lat, field, **plot_basemap_kwargs)
return fig
# ==================================================================================================================== #
# CFSReanalysis object class
# ==================================================================================================================== #
示例6: _basemap_get_quicklook
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def _basemap_get_quicklook(area_def, data, vmin=None, vmax=None,
label='Variable (units)', num_meridians=45,
num_parallels=10, coast_res='110m', cmap='RdBu_r'):
"""Doing quicklook image plots with Basemap."""
if area_def.shape != data.shape:
raise ValueError('area_def shape %s does not match data shape %s' %
(list(area_def.shape), list(data.shape)))
import matplotlib.pyplot as plt
bmap = area_def2basemap(area_def, resolution=coast_res)
bmap.drawcoastlines()
if num_meridians > 0:
bmap.drawmeridians(np.arange(-180, 180, num_meridians))
if num_parallels > 0:
bmap.drawparallels(np.arange(-90, 90, num_parallels))
if not (np.ma.isMaskedArray(data) and data.mask.all()):
col = bmap.imshow(data, origin='upper', vmin=vmin, vmax=vmax, cmap=cmap)
plt.colorbar(col, shrink=0.5, pad=0.05).set_label(label)
return plt
示例7: draw_geolines
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def draw_geolines(area, dlon, dlat, basemap, linewidth=1):
"""
Draw the parallels and meridians on a basemap plot.
Parameters:
* area : list
``[west, east, south, north]``, i.e., the area where the lines will
be plotted
* dlon, dlat : float
The spacing between the lines in the longitude and latitude directions,
respectively (in decimal degrees)
* basemap : mpl_toolkits.basemap.Basemap
The basemap used for plotting (see :func:`~geoist.vis.giplt.basemap`)
* linewidth : float
The width of the lines
"""
west, east, south, north = area
basemap.drawmeridians(numpy.arange(west, east, dlon), labels=[0, 0, 0, 1],
linewidth=linewidth)
basemap.drawparallels(numpy.arange(south, north, dlat),
labels=[1, 0, 0, 0], linewidth=linewidth)
示例8: draw_countries
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def draw_countries(basemap, linewidth=1, style='dashed'):
"""
Draw the country borders using the given basemap.
Parameters:
* basemap : mpl_toolkits.basemap.Basemap
The basemap used for plotting (see :func:`~geoist.vis.giplt.basemap`)
* linewidth : float
The width of the lines
* style : str
The style of the lines. Can be: 'solid', 'dashed', 'dashdot' or
'dotted'
"""
lines = basemap.drawcountries(linewidth=linewidth)
lines.set_linestyles(style)
示例9: draw_coastlines
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def draw_coastlines(basemap, linewidth=1, style='solid'):
"""
Draw the coastlines using the given basemap.
Parameters:
* basemap : mpl_toolkits.basemap.Basemap
The basemap used for plotting (see :func:`~geoist.vis.giplt.basemap`)
* linewidth : float
The width of the lines
* style : str
The style of the lines. Can be: 'solid', 'dashed', 'dashdot' or
'dotted'
"""
lines = basemap.drawcoastlines(linewidth=linewidth)
lines.set_linestyles(style)
示例10: polar_stere
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def polar_stere(lon_w, lon_e, lat_s, lat_n, **kwargs):
'''Returns a Basemap object (NPS/SPS) focused in a region.
lon_w, lon_e, lat_s, lat_n -- Graphic limits in geographical coordinates.
W and S directions are negative.
**kwargs -- Aditional arguments for Basemap object.
'''
lon_0 = lon_w + (lon_e - lon_w) / 2.
ref = lat_s if abs(lat_s) > abs(lat_n) else lat_n
lat_0 = math.copysign(90., ref)
proj = 'npstere' if lat_0 > 0 else 'spstere'
prj = Basemap(projection=proj, lon_0=lon_0, lat_0=lat_0,
boundinglat=0, resolution='l')
#prj = pyproj.Proj(proj='stere', lon_0=lon_0, lat_0=lat_0)
lons = [lon_w, lon_e, lon_w, lon_e, lon_0, lon_0]
lats = [lat_s, lat_s, lat_n, lat_n, lat_s, lat_n]
x, y = prj(lons, lats)
ll_lon, ll_lat = prj(min(x), min(y), inverse=True)
ur_lon, ur_lat = prj(max(x), max(y), inverse=True)
return Basemap(projection='stere', lat_0=lat_0, lon_0=lon_0,
llcrnrlon=ll_lon, llcrnrlat=ll_lat,
urcrnrlon=ur_lon, urcrnrlat=ur_lat, round=True,
resolution='l')
示例11: draw_terrain_height_map
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def draw_terrain_height_map(self, fig, ax, vmin=None, vmax=None,
lat_spacing=None, lon_spacing=None):
'''Draw the terrain heights'''
if vmin is None:
topomin = 0.05
else:
topomin = vmin/1000.
if vmax is None:
topomax = 3.
else:
topomax = vmax/1000.
if lat_spacing is None:
lat_spacing = 1.
if lon_spacing is None:
lon_spacing = 1.
bm1 = Basemap(projection='cea', resolution='l', area_thresh = 10000.,
llcrnrlon=self.minlon, urcrnrlon=self.maxlon,
llcrnrlat=self.minlat, urcrnrlat=self.maxlat,
ax=ax)
ax.set_title('Terrain within %02d km of Radar (km)'%(self.range), fontdict=TITLEDICT)
bm1.drawmeridians(np.arange(self.minlon, self.maxlon, lon_spacing), labels=[1,0,0,1])
bm1.drawparallels(np.arange(self.minlat, self.maxlat, lat_spacing), labels=[1,0,0,1])
bm1.drawcountries()
bm1.drawcoastlines()
bm1.drawrivers()
xbm1, ybm1 = bm1(self.lon, self.lat)
Htmap = bm1.pcolormesh(xbm1, ybm1, self.topo/1000., vmin=topomin, vmax=topomax,
cmap=self.terr_cmap)
bm1.plot(self.rlon, self.rlat, 'rD', latlon=True)
#plot_range_ring(50., bm=bm1, color='w')
fig.colorbar(Htmap, ax=ax)
示例12: draw_bb_map
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def draw_bb_map(self, fig, ax, BB=None, range_rings=None,
lat_spacing=None, lon_spacing=None):
'''Draw the Beam Blockage'''
if BB is None:
BB = self.CBB
if lat_spacing is None:
lat_spacing = 1.
if lon_spacing is None:
lon_spacing = 1.
bm2 = Basemap(projection='cea', resolution='l', area_thresh = 10000.,
llcrnrlon=self.minlon, urcrnrlon=self.maxlon,
llcrnrlat=self.minlat, urcrnrlat=self.maxlat,
ax=ax)
ax.set_title('Beam-blockage fraction', fontdict=TITLEDICT)
bm2.drawmeridians(np.arange(self.minlon, self.maxlon, lon_spacing), labels=[1,0,0,1])
bm2.drawparallels(np.arange(self.minlat, self.maxlat, lat_spacing), labels=[1,0,0,1])
bm2.drawcountries()
bm2.drawcoastlines()
bm2.drawrivers()
xbm2, ybm2 = bm2(self.rng_lon, self.rng_lat)
BBmap = bm2.pcolormesh(xbm2, ybm2, BB, vmin=0., vmax=1., cmap=self.bb_cmap)
if range_rings is not None:
for nn in range(len(range_rings)):
self.plot_range_ring(range_rings[nn], bm=bm2)
fig.colorbar(BBmap, ax=ax)
示例13: create_map
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def create_map(lon, lat):
"""
Create a map projection.
"""
lon_center = lon[0]
lat_center = lat[0]
return Basemap(
lon_0=lon_center,
lat_0=lat_center, projection='tmerc',
width=1e-5, height=1e-5)
示例14: project_lat_lon
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def project_lat_lon(df):
gps_map = Basemap(lat_0=df.GPS_Lat.values[0],
lon_0=df.GPS_Lon.values[0],
width=11e-5, height=1e-5, projection='tmerc')
gps_y, gps_x = gps_map(df.GPS_Lon.values, df.GPS_Lat.values)
gps_z = df.GPS_Alt - df.GPS_Alt.values[0]
df_new = pandas.DataFrame(pandas.DataFrame({
'GPS_X': gps_x, 'GPS_Y': gps_y, 'GPS_Z': gps_z}, index=df.index))
return pandas.concat([df, df_new], axis=1)
# vim: set et fenc= ff=unix sts=0 sw=4 ts=4 :
示例15: basemap_from_file
# 需要导入模块: from mpl_toolkits import basemap [as 别名]
# 或者: from mpl_toolkits.basemap import Basemap [as 别名]
def basemap_from_file(ifile, withgrid=False, **kwds):
"""
Typically, the user will need to provide some options
"""
proj4 = getproj4(ifile, withgrid=withgrid)
basemap_options = basemap_options_from_proj4(proj4, **kwds)
if 'llcrnrx' in basemap_options:
if 'urcrnrx' in kwds:
basemap_options['urcrnrx'] = kwds['urcrnrx']
elif 'width' in kwds:
basemap_options['urcrnrx'] = basemap_options['llcrnrx'] + \
kwds['width']
elif 'x' in ifile.variables:
x = ifile.variables['x']
urx = x.max() + np.mean(np.diff(x))
basemap_options['urcrnrx'] = urx
else:
raise KeyError(
'When a false_easting is available, the file must contain ' +
'an x variable or the user must supply width or urcrnrx')
if 'llcrnry' in basemap_options:
if 'urcrnry' in kwds:
basemap_options['urcrnry'] = kwds['urcrnry']
elif 'height' in kwds:
basemap_options['urcrnry'] = basemap_options['llcrnry'] + \
kwds['height']
elif 'y' in ifile.variables:
y = ifile.variables['y']
ury = y.max() + np.mean(np.diff(y))
basemap_options['urcrnry'] = ury
else:
raise KeyError(
'When a false_northing is available, the file must contain ' +
'a y variable or the user must supply height or urcrnry')
from mpl_toolkits.basemap import Basemap
print(basemap_options)
bmap = Basemap(**basemap_options)
return bmap