当前位置: 首页>>代码示例>>Python>>正文


Python cartopy.crs方法代码示例

本文整理汇总了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 
开发者ID:climate-processes,项目名称:tobac,代码行数:20,代码来源:plotting.py

示例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())) 
开发者ID:PyPSA,项目名称:PyPSA,代码行数:19,代码来源:plot.py

示例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() 
开发者ID:climate-processes,项目名称:tobac,代码行数:31,代码来源:plotting.py

示例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 
开发者ID:climate-processes,项目名称:tobac,代码行数:29,代码来源:plotting.py

示例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() 
开发者ID:PyPSA,项目名称:PyPSA,代码行数:16,代码来源:plot.py

示例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 
开发者ID:PyPSA,项目名称:PyPSA,代码行数:31,代码来源:plot.py


注:本文中的cartopy.crs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。