本文整理汇总了Python中mpl_toolkits.basemap.Basemap.drawstates方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.drawstates方法的具体用法?Python Basemap.drawstates怎么用?Python Basemap.drawstates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpl_toolkits.basemap.Basemap
的用法示例。
在下文中一共展示了Basemap.drawstates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def main():
plot_utils.apply_plot_params(width_cm=20, height_cm=20, font_size=10)
high_hles_years = [1993, 1995, 1998]
low_hles_years = [1997, 2001, 2006]
data_path = "/BIG1/skynet1_rech1/diro/sample_obsdata/eraint/eraint_uvslp_years_198111_201102_NDJmean_ts.nc"
with xr.open_dataset(data_path) as ds:
print(ds)
u = get_composit_for_name(ds, "u10", high_years_list=high_hles_years, low_years_list=low_hles_years)
v = get_composit_for_name(ds, "v10", high_years_list=high_hles_years, low_years_list=low_hles_years)
msl = get_composit_for_name(ds, "msl", high_years_list=high_hles_years, low_years_list=low_hles_years)
lons = ds["longitude"].values
lats = ds["latitude"].values
print(lats)
print(msl.shape)
print(lons.shape, lats.shape)
lons2d, lats2d = np.meshgrid(lons, lats)
fig = plt.figure()
map = Basemap(llcrnrlon=-130, llcrnrlat=22, urcrnrlon=-28,
urcrnrlat=65, projection='lcc', lat_1=33, lat_2=45,
lon_0=-95, resolution='i', area_thresh=10000)
clevs = np.arange(-11.5, 12, 1)
cmap = cm.get_cmap("bwr", len(clevs) - 1)
bn = BoundaryNorm(clevs, len(clevs) - 1)
x, y = map(lons2d, lats2d)
im = map.contourf(x, y, msl / 100, levels=clevs, norm=bn, cmap=cmap) # convert to mb (i.e hpa)
map.colorbar(im)
stride = 2
ux, vy = map.rotate_vector(u, v, lons2d, lats2d)
qk = map.quiver(x[::stride, ::stride], y[::stride, ::stride], ux[::stride, ::stride], vy[::stride, ::stride],
scale=10, width=0.01, units="inches")
plt.quiverkey(qk, 0.5, -0.1, 2, "2 m/s", coordinates="axes")
map.drawcoastlines(linewidth=0.5)
map.drawcountries()
map.drawstates()
#plt.show()
fig.savefig("hles_wind_compoosits.png", bbox_inches="tight", dpi=300)
示例2: plot_filtered_diff
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot_filtered_diff(self):
"""
function for plotting the difference of filtered vorticity
"""
w_diff, lon, lat, mask = self.vorticity_filter()
south = lat.min(); north =lat.max()
west = lon.min(); east = lon.max()
timeformat = '%Y%m%d-%H%M'
for i in range(len(self.time)):
fig = plt.figure(figsize=(10,8))
basemap = Basemap(projection='merc',llcrnrlat=south,urcrnrlat=north,\
llcrnrlon=west,urcrnrlon=east, resolution='h')
basemap.drawcoastlines()
basemap.fillcontinents(color='coral',lake_color='aqua')
basemap.drawcountries()
basemap.drawstates()
llons, llats=basemap(lon,lat)
con = basemap.pcolormesh(llons,llats,w_diff[i,:,:])
#con.set_clim(vmin=-0.0003, vmax=0.0003)
cbar = plt.colorbar(con, orientation='vertical')
cbar.set_label("vorticity")
#plt.show()
timestr = datetime.strftime(self.time[i], timeformat)
plt.title('vorticity at %s'%timestr)
plt.savefig(self.wdr+'/vorticity_figure/vorticity_diff/'+str(i)+'.png')
print "Saving figure %s to ROMS figure directory"%str(i)
示例3: plot_map_twts
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot_map_twts(twts, title='default title'):
"""
Given an iterable of 'clean' tweets, make a dot map over North America.
"""
fig1 = plt.figure()
ax = fig1.add_subplot(111)
m = Basemap(projection='merc',
resolution = 'l',
llcrnrlon=-136.0, llcrnrlat=24.0,
urcrnrlon=-67.0, urcrnrlat=60.0,
ax=ax)
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color = 'coral', alpha=0.5)
m.drawmapboundary()
lons = [twt['coordinates'][0] for twt in twts]
lats = [twt['coordinates'][1] for twt in twts]
x,y = m(lons, lats)
m.plot(x, y, 'bo', markersize=5)
plt.title(title)
plt.show()
示例4: plot_us
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot_us(lats, lons, save_name=None):
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
big_map = Basemap(resolution='h',
lat_0=36, lon_0=-107.5,
llcrnrlat=32, llcrnrlon=-125,
urcrnrlat=43, urcrnrlon=-110)
big_map.drawcoastlines()
big_map.drawstates()
big_map.drawcountries()
big_map.drawmapboundary(fill_color='#7777ff')
big_map.fillcontinents(color='#ddaa66', lake_color='#7777ff', zorder=0)
x, y = big_map(lons, lats)
big_map.plot(x[0], y[0], 'ro', markersize=2)
axins = zoomed_inset_axes(ax, 20, loc=1)
ll_lat, ll_lon = 37.8, -122.78
ur_lat, ur_lon = 38.08, -122.43
axins.set_xlim(ll_lon, ur_lon)
axins.set_ylim(ur_lon, ur_lat)
small_map = Basemap(resolution='h',
llcrnrlat=ll_lat, llcrnrlon=ll_lon,
urcrnrlat=ur_lat, urcrnrlon=ur_lon,
ax=axins)
small_map.drawcoastlines()
small_map.drawmapboundary(fill_color='#7777ff')
small_map.fillcontinents(color='#ddaa66', lake_color='#7777ff', zorder=0)
x, y = small_map(lons, lats)
small_map.plot(x, y, 'ro', markersize=3)
mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5")
if save_name:
fig.savefig(save_name)
示例5: worldplot
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def worldplot(self,kmeans=None,proj='merc'):
"""
plots customer GPS location on a map with state and national boundaries.
IN
kmeans (int) number of means for k-means clustering, default=None
proj (string) the map projection to use, use 'robin' to plot the whole earth, default='merc'
"""
# create a matplotlib Basemap object
if proj == 'robin':
my_map = Basemap(projection=proj,lat_0=0,lon_0=0,resolution='l',area_thresh=1000)
else:
my_map = Basemap(projection=proj,lat_0=33.,lon_0=-125.,resolution='l',area_thresh=1000.,
llcrnrlon=-130.,llcrnrlat=25,urcrnrlon=-65., urcrnrlat=50)
my_map.drawcoastlines(color='grey')
my_map.drawcountries(color='grey')
my_map.drawstates(color='grey')
my_map.drawlsmask(land_color='white',ocean_color='white')
my_map.drawmapboundary() #my_map.fillcontinents(color='black')
x,y = my_map(np.array(self.data['lon']),np.array(self.data['lat']))
my_map.plot(x,y,'ro',markersize=3,alpha=.4,linewidth=0)
if kmeans:
# k-means clustering algorithm---see wikipedia for details
data_in = self.data.drop(['id','clv','level'],axis=1)
# vq is scipy's vector quantization module
output,distortion = vq.kmeans(data_in,kmeans)
x1,y1 = my_map(output[:,1],output[:,0])
my_map.plot(x1,y1,'ko',markersize=20,alpha=.4,linewidth=0)
plt.show()
return output
示例6: Scatter
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def Scatter(data, lons, lats, min, max, cmp, tit, unit, figdir, filename):
# Prepare for drawing
# ny, nx = (50, 116)
# draw Chile Basemap with lambert projection at normal x, y settings
m = Basemap(
llcrnrlon=-78,
llcrnrlat=-56,
urcrnrlon=-66,
urcrnrlat=-17,
projection="cyl",
fix_aspect=False,
lat_1=-43,
lat_2=-30,
lon_0=-72,
) # projection='lcc'
# draw boundaries
m.drawcoastlines()
m.drawcountries(linewidth=2)
m.drawstates()
m.drawparallels(arange(-60, -15, 15), labels=[1, 0, 0, 0]) # only left ytick
m.drawmeridians(arange(-80, -60, 5), labels=[0, 0, 0, 1]) # only bottom xtick
# map data with lon and lat position
im = m.scatter(lons, lats, 30, marker="o", c=data, vmin=min, vmax=max, latlon=True, cmap=cmp)
cb = m.colorbar(im, pad="10%")
plt.title(tit, fontsize=20)
plt.xlabel(unit, labelpad=50)
# savefig('%s%s' % (figdir, filename))
plt.show()
示例7: plot_grid2D
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot_grid2D(lons, lats, tec_grid2D, datetime, title_label = ''):
LATS, LONS = np.meshgrid(lats, lons)
m = Basemap(llcrnrlon=-180,
llcrnrlat=-55,
urcrnrlon=180,
urcrnrlat=75,
projection='merc',
area_thresh=1000,
resolution='i')
m.drawstates()
m.drawcountries()
m.drawcoastlines()
parallels = np.arange(-90,90,20)
m.drawparallels(parallels,labels=[True,False,False,True])
meridians = np.arange(0,360,40)
m.drawmeridians(meridians,labels=[True,False,False,True])
m.scatter(LONS, LATS, c=tec_grid2D, latlon = True, linewidths=0, s=5)
m.colorbar()
plt.title('%s\n%s' % (title_label, datetime.isoformat(' ')))
示例8: displaymap
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def displaymap(region=__AUSREGION__,
subregions=[], labels=[], colors=[], linewidths=[],
fontsize='small', bluemarble=True, drawstates=True):
'''
regions are [lat,lon,lat,lon]
'''
m = Basemap(projection='mill', resolution='f',
llcrnrlon=region[1], llcrnrlat=region[0],
urcrnrlon=region[3], urcrnrlat=region[2])
if bluemarble:
m.bluemarble()
else:
m.drawcountries()
if drawstates:
m.drawstates()
# Add lats/lons to map
add_grid_to_map(m,xy0=(-10,-80),xyres=(10,10),dashes=[1,1e6],labels=[1,0,0,1])
for r in subregions:
if len(labels)<len(r):
labels.append('')
if len(colors)<len(r):
colors.append('k')
if len(linewidths)<len(r):
linewidths.append(1)
# add subregions and little lables:
for r,l,c,lw in zip(subregions, labels, colors, linewidths):
plot_rec(m,r,color=c, linewidth=lw)
lon,lat=r[1],r[2]
x,y = m(lon,lat)
plt.text(x+100,y-130,l,fontsize=fontsize,color=c)
return m
示例9: draw
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def draw(self, pop):
fig=plt.figure()
ax=fig.add_axes([0.1,0.1,0.8,0.8])
m = Basemap(llcrnrlon=-125.,llcrnrlat=25.,urcrnrlon=-65.,urcrnrlat=52.,
rsphere=(6378137.00,6356752.3142),
resolution='l',projection='merc',
lat_0=40.,lon_0=-20.,lat_ts=20.)
l = pop[0]
for i in range(len(l.sol)):
lat1 = l.sol[i].lat
lon1 = l.sol[i].lon
m.drawgreatcircle(lon1,lat1,lon1,lat1, linewidth=4, color = 'r')
if i == len(l.sol) - 1:
lat2 = l.sol[0].lat
lon2 = l.sol[0].lon
else:
lat2 = l.sol[i+1].lat
lon2 = l.sol[i+1].lon
m.drawgreatcircle(lon1,lat1,lon2,lat2, color = 'b')
m.drawcoastlines()
m.drawstates()
m.drawcountries()
m.fillcontinents()
ax.set_title('GREEDY')
plt.show()
示例10: plotRegion
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plotRegion(expertiseRegions, models):
colors = ["red", "aqua", "blue", "green", "yellow", "magenta", "purple", "grey", "violet", "white"]
# llcrnrlat,llcrnrlon,urcrnrlat,urcrnrlon
# are the lat/lon values of the lower left and upper right corners
# of the map.
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
m = Basemap(projection="merc", llcrnrlon=-129, llcrnrlat=27, urcrnrlon=-60, urcrnrlat=50, lat_ts=20, resolution="c")
m.drawcoastlines()
m.fillcontinents(color="coral", lake_color="aqua")
# draw parallels and meridians.
m.drawstates()
lon = -125.3318
lat = 37.0799
x, y = m(lon, lat)
index = 0
for region in expertiseRegions:
lats = [region._leftTop[0], region._rightBottom[0], region._rightBottom[0], region._leftTop[0]]
lons = [region._leftTop[1], region._leftTop[1], region._rightBottom[1], region._rightBottom[1]]
draw_screen_poly(lats, lons, m, color=colors[index])
for model in models:
x = model["center"][0]
y = model["center"][1]
m.plot(x, y, "bo", markersize=10)
m.drawmapboundary(fill_color="aqua")
plt.title("Expert Regions")
plt.savefig("region.png")
plt.clf()
示例11: plot_quakes
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot_quakes(years, figsize, quantity):
res = get_plot_res(years)
colors = get_colormap(years)
quakes = get_quakes_subset(years, quantity)
lat_0 = quakes['LAT'].mean()
lon_0 = quakes['LON'].mean()
fig = matplotlib.pyplot.figure(figsize=figsize)
m = Basemap(resolution = res, projection='nsper',
area_thresh = 1000., satellite_height = 200000,
lat_0 = lat_0, lon_0 = lon_0)
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color = 'green', lake_color = 'aqua')
m.drawmapboundary(fill_color = 'blue')
x, y = m(quakes.LON, quakes.LAT)
for i in range(0, len(x) - 1):
color = colors[get_year(quakes[i:i+1])-years[0]]
m.plot(x[i:i+1], y[i:i+1], color = color,
marker = 'o', markersize = (pi*(quakes.MAG[i:i+1]).apply(float)**2),
alpha = 0.5)
示例12: nice_plot
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def nice_plot(data,xmin,xmax,xint,centerlat,centerlon,stations,color,cmin,
cmax,levels_t):
"""Make plots in map projection, requires input array, x-min max and
interval (also used for y), center of data in lat, lon, station
locations, color scale, min and max limits and levels array for color
scale.
"""
domain = xmax-xint/2.
maps = Basemap(projection='laea',lat_0=centerlat,lon_0=centerlon,
width=domain*2,height=domain*2)
s = plt.pcolormesh(np.arange(xmin-xint/2.,xmax+3*xint/2.,xint)+domain,
np.arange(xmin-xint/2.,xmax+3*xint/2.,xint)+domain,
data, cmap = color)
s.set_clim(vmin=cmin,vmax=cmax)
CS = plt.contour(np.arange(xmin,xmax+xint,xint)+domain,
np.arange(xmin,xmax+xint,xint)+domain,
data, colors='k',levels=levels_t)
plt.clabel(CS, inline=1, fmt='%1.2f',fontsize=8)
plt.scatter(stations[:,0]+domain, stations[:,1]+domain, color='k',s=2)
maps.drawstates()
fig = plt.gcf()
circle=plt.Circle((domain,domain),100000,color='0.5',fill=False)
fig.gca().add_artist(circle)
circle=plt.Circle((domain,domain),200000,color='0.5',fill=False)
fig.gca().add_artist(circle)
示例13: visualize
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def visualize(self):
"""
Visuzalise the edges
References:
* http://stackoverflow.com/questions/11603537/plot-multiple-lines-in-python-basemap
"""
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
m = Basemap(projection='mill', llcrnrlat=self.bounds[0], urcrnrlat=self.bounds[2],
llcrnrlon=self.bounds[1], urcrnrlon=self.bounds[3], resolution='c')
m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.fillcontinents(color='#EEEEEE', lake_color='#FFFFFF')
m.drawmapboundary(fill_color='#FFFFFF')
# Plotting segments
for path in self.get_paths():
latlngs = np.array(map(lambda node: (node.lat, node.lng), path.get_nodes()))
x, y = m(latlngs.T[1], latlngs.T[0])
m.plot(x, y, color="#000000", marker='o', linestyle='-', linewidth=2, alpha=.5)
plt.title('Segment plotting')
plt.show()
示例14: plot
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def plot(self,reports,itime,ftime,fname,outdir,Nlim=False,
Elim=False,Slim=False,Wlim=False,
annotate=True,fig=False,ax=False,ss=50,color='blue'):
reportidx = N.array([n for n,t in zip(range(len(self.r['EVENT_TYPE'])),self.r['EVENT_TYPE']) if reports in t])
lateidx = N.where(self.datetimes > itime)
earlyidx = N.where(self.datetimes < ftime)
timeidx = N.intersect1d(earlyidx,lateidx,)#assume_unique=True)
plotidx = N.intersect1d(reportidx,timeidx)
from mpl_toolkits.basemap import Basemap
if fig==False:
fig,ax = plt.subplots(1,figsize=(6,6))
m = Basemap(projection='merc',
llcrnrlat=Slim,
llcrnrlon=Wlim,
urcrnrlat=Nlim,
urcrnrlon=Elim,
lat_ts=(Nlim-Slim)/2.0,
resolution='i',
ax=ax)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
m.scatter(self.r['BEGIN_LON'][plotidx],self.r['BEGIN_LAT'][plotidx],latlon=True,
marker='D',facecolors=color,edgecolors='black',s=ss)
fig.tight_layout()
plt.savefig(os.path.join(outdir,fname))
示例15: get_catalog_map
# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import drawstates [as 别名]
def get_catalog_map(lats=None, lons=None, eq_cat=[], map_res='i', map_projection='cyl', fignum=0, ax=None, do_clf=True):
#
if lats==None: lats = [31., 42.]
if lons==None: lons = [-125., -114.]
#
if fignum!=None: plt.figure(fignum)
if do_clf: plt.clf()
if ax==None: ax=plt.gca()
#
cm = Basemap(llcrnrlon=lons[0], llcrnrlat=lats[0], urcrnrlon=lons[1], urcrnrlat=lats[1], resolution=map_res, projection=map_projection, lon_0=numpy.mean(lons), lat_0=numpy.mean(lats), ax=ax)
cm.drawcoastlines(color='gray', zorder=1)
cm.drawcountries(color='gray', zorder=1)
cm.drawstates(color='gray', zorder=1)
cm.drawrivers(color='gray', zorder=1)
cm.fillcontinents(color='beige', zorder=0)
# drawlsmask(land_color='0.8', ocean_color='w', lsmask=None, lsmask_lons=None, lsmask_lats=None, lakes=True, resolution='l', grid=5, **kwargs)
#cm.drawlsmask(land_color='0.8', ocean_color='c', lsmask=None, lsmask_lons=None, lsmask_lats=None, lakes=True, resolution=mapres, grid=5)
print("lat, lon ranges: ", lats, lons)
cm.drawmeridians(list(range(int(lons[0]), int(lons[1]))), color='k', labels=[0,0,1,1])
cm.drawparallels(list(range(int(lats[0]), int(lats[1]))), color='k', labels=[1, 1, 0, 0])
#
if eq_cat!=None:
# can we also assign sizes dynamically, like colors?
if hasattr(eq_cat, 'dtype'):
# it's a recrray:
X,Y = cm(eq_cat['lon'], eq_cat['lat'])
else:
# it's probably a list... though we should check for dicts, etc.
X,Y = cm([rw[2] for rw in eq_cat], [rw[1] for rw in eq_cat])
#
cm.plot(X,Y, '.')
#
return cm