本文整理匯總了Python中cartopy.crs方法的典型用法代碼示例。如果您正苦於以下問題:Python cartopy.crs方法的具體用法?Python cartopy.crs怎麽用?Python cartopy.crs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cartopy
的用法示例。
在下文中一共展示了cartopy.crs方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_map
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def make_map(axes):
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
gl = axes.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=2, color='gray', alpha=0.5, linestyle='-')
axes.coastlines('10m')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xlocator = mticker.MaxNLocator(nbins=5,min_n_ticks=3,steps=None)
gl.ylocator = mticker.MaxNLocator(nbins=5,min_n_ticks=3,steps=None)
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
#gl.xlabel_style = {'size': 15, 'color': 'gray'}
#gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
return axes
示例2: projected_area_factor
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def projected_area_factor(ax, original_crs=4326):
"""
Helper function to get the area scale of the current projection in
reference to the default projection. The default 'original crs' is assumed
to be 4326, which translates to the cartopy default cartopy.crs.PlateCarree()
"""
if not hasattr(ax, 'projection'):
return 1
if isinstance(ax.projection, ccrs.PlateCarree):
return 1
x1, x2, y1, y2 = ax.get_extent()
pbounds = \
get_projection_from_crs(original_crs).transform_points(ax.projection,
np.array([x1, x2]), np.array([y1, y2]))
return np.sqrt(abs((x2 - x1) * (y2 - y1))
/abs((pbounds[0] - pbounds[1])[:2].prod()))
示例3: plot_tracks_mask_field_loop
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def plot_tracks_mask_field_loop(track,field,mask,features,axes=None,name=None,plot_dir='./',
figsize=(10./2.54,10./2.54),dpi=300,
margin_left=0.05,margin_right=0.05,margin_bottom=0.05,margin_top=0.05,
**kwargs):
import cartopy.crs as ccrs
import os
from iris import Constraint
os.makedirs(plot_dir,exist_ok=True)
time=mask.coord('time')
if name is None:
name=field.name()
for time_i in time.points:
datetime_i=time.units.num2date(time_i)
constraint_time = Constraint(time=datetime_i)
fig1,ax1=plt.subplots(ncols=1, nrows=1,figsize=figsize, subplot_kw={'projection': ccrs.PlateCarree()})
datestring_file=datetime_i.strftime('%Y-%m-%d_%H:%M:%S')
field_i=field.extract(constraint_time)
mask_i=mask.extract(constraint_time)
track_i=track[track['time']==datetime_i]
features_i=features[features['time']==datetime_i]
ax1=plot_tracks_mask_field(track=track_i,field=field_i,mask=mask_i,features=features_i,
axes=ax1,**kwargs)
fig1.subplots_adjust(left=margin_left, bottom=margin_bottom, right=1-margin_right, top=1-margin_top)
os.makedirs(plot_dir, exist_ok=True)
savepath_png=os.path.join(plot_dir,name+'_'+datestring_file+'.png')
fig1.savefig(savepath_png,dpi=dpi)
logging.debug('Figure plotted to ' + str(savepath_png))
plt.close()
示例4: animation_mask_field
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def animation_mask_field(track,features,field,mask,interval=500,figsize=(10,10),**kwargs):
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.animation
from iris import Constraint
fig=plt.figure(figsize=figsize)
plt.close()
def update(time_in):
fig.clf()
ax=fig.add_subplot(111,projection=ccrs.PlateCarree())
constraint_time = Constraint(time=time_in)
field_i=field.extract(constraint_time)
mask_i=mask.extract(constraint_time)
track_i=track[track['time']==time_in]
features_i=features[features['time']==time_in]
#fig1,ax1=plt.subplots(ncols=1, nrows=1,figsize=figsize, subplot_kw={'projection': ccrs.PlateCarree()})
plot_tobac=plot_tracks_mask_field(track_i,field=field_i,mask=mask_i,features=features_i,
axes=ax,
**kwargs)
ax.set_title('{}'.format(time_in))
time=field.coord('time')
datetimes=time.units.num2date(time.points)
animation = matplotlib.animation.FuncAnimation(fig, update,init_func=None, frames=datetimes,interval=interval, blit=False)
return animation
示例5: get_projection_from_crs
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def get_projection_from_crs(crs):
if crs == 4326:
# if data is in latlon system, return default map with latlon system
return ccrs.PlateCarree()
try:
return ccrs.epsg(crs)
except requests.RequestException:
logger.warning("A connection to http://epsg.io/ is "
"required for a projected coordinate reference system. "
"Falling back to latlong.")
except ValueError:
logger.warning("'{crs}' does not define a projected coordinate system. "
"Falling back to latlong.".format(crs=crs))
return ccrs.PlateCarree()
示例6: draw_map_cartopy
# 需要導入模塊: import cartopy [as 別名]
# 或者: from cartopy import crs [as 別名]
def draw_map_cartopy(n, x, y, ax, boundaries=None, margin=0.05,
geomap=True, color_geomap=None):
if boundaries is None:
(x1, y1), (x2, y2) = compute_bbox_with_margins(margin, x, y)
else:
x1, x2, y1, y2 = boundaries
resolution = '50m' if isinstance(geomap, bool) else geomap
assert resolution in ['10m', '50m', '110m'], (
"Resolution has to be one of '10m', '50m', '110m'")
axis_transformation = get_projection_from_crs(n.srid)
ax.set_extent([x1, x2, y1, y2], crs=axis_transformation)
if color_geomap is None:
color_geomap = {'ocean': 'w', 'land': 'w'}
elif color_geomap and not isinstance(color_geomap, dict):
color_geomap = {'ocean': 'lightblue', 'land': 'whitesmoke'}
ax.add_feature(cartopy.feature.LAND.with_scale(resolution),
facecolor=color_geomap['land'])
ax.add_feature(cartopy.feature.OCEAN.with_scale(resolution),
facecolor=color_geomap['ocean'])
ax.coastlines(linewidth=0.4, zorder=2, resolution=resolution)
border = cartopy.feature.BORDERS.with_scale(resolution)
ax.add_feature(border, linewidth=0.3)
return axis_transformation