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


Python Basemap.artists方法代码示例

本文整理汇总了Python中mpl_toolkits.basemap.Basemap.artists方法的典型用法代码示例。如果您正苦于以下问题:Python Basemap.artists方法的具体用法?Python Basemap.artists怎么用?Python Basemap.artists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpl_toolkits.basemap.Basemap的用法示例。


在下文中一共展示了Basemap.artists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_basemap

# 需要导入模块: from mpl_toolkits.basemap import Basemap [as 别名]
# 或者: from mpl_toolkits.basemap.Basemap import artists [as 别名]
def build_basemap(lower_left=[-20,-30],upper_right=[20,10],ax=None,proj='cyl',profile=None,larger=True):
    """
    First try at a building of the basemap with a 'stere' projection
    Must put in the values of the lower left corner and upper right corner (lon and lat)
    
    Defaults to draw 8 meridians and parallels

    Modified: Samuel LeBlanc, 2015-09-15, NASA Ames
            - added profile keyword that contains the basemap profile dict for plotting the corners
            - added programatic determination of basemap parallels and meridians
    Modified: Samuel LeBlanc, 2016-07-17, Santa Cruz, CA
            - added plotting of larger region, which is then resized, to have space to pan and zoom.
    """
    from map_interactive import pll
    if profile:
        upper_right = [pll(profile['Lon_range'][1]),pll(profile['Lat_range'][1])]
        lower_left = [pll(profile['Lon_range'][0]),pll(profile['Lat_range'][0])]

    if larger:
        dp = 30
    else:
        dp = 0
    try:
        import cPickle as pickle
        m = pickle.load(open('map_{}.pkl'.format(profile['Campaign']),'rb'))
        #print 'doing it pickle style'
        m.ax = ax
    except:
        if larger:
            dp = 30
        else:
            dp = 0
        m = Basemap(projection=proj,lon_0=(upper_right[0]+lower_left[0])/2.0,lat_0=(upper_right[1]+lower_left[1])/2.0,
                llcrnrlon=lower_left[0]-dp, llcrnrlat=lower_left[1]-dp,
                urcrnrlon=upper_right[0]+dp, urcrnrlat=upper_right[1]+dp,resolution='i',ax=ax)
    m.artists = []
    m.drawcoastlines()
    #m.fillcontinents(color='#AAAAAA')
    m.drawstates()
    m.drawcountries()
    m.large = True
    round_to_5 = lambda x:(int(x/5)+1)*5 
    round_to_2 = lambda x:(int(x/2)+1)*2
    if (upper_right[0]-lower_left[0])<20.0:
        mer = np.arange(round_to_2(lower_left[0]-dp),round_to_2(upper_right[0]+dp)+2,2)
        difx = 0.2
        m.large = False
    else:
        mer = np.arange(round_to_5(lower_left[0]-dp),round_to_5(upper_right[0]+dp)+5,5)
        difx = 1.0
    if (upper_right[1]-lower_left[1])<20.0:
        par = np.arange(round_to_2(lower_left[1]-dp),round_to_2(upper_right[1]+dp)+2,2)
        dify = 0.2
        m.large = False
    else:
        par = np.arange(round_to_5(lower_left[1]-dp),round_to_5(upper_right[1]+dp)+5,5)
        dify = 1.0
    if ax:
        ax.set_xlim(lower_left[0],upper_right[0])
        ax.set_ylim(lower_left[1],upper_right[1])
    m.artists.append(m.drawmeridians(mer,labels=[0,0,0,1]))
    m.artists.append(m.drawparallels(par,labels=[1,0,0,0]))
    # move the meridian labels to a proper position
    for aa in m.artists[0].keys():
        try:
            m.artists[0][aa][1][0].set_position((m.artists[0][aa][1][0].get_position()[0],lower_left[1]-difx))
        except:
            pass
    # move the parallels labels to a proper position
    for aa in m.artists[1].keys():
        try:
            m.artists[1][aa][1][0].set_position((lower_left[0]-dify,m.artists[1][aa][1][0].get_position()[1]))
        except:
            pass
    #import pdb; pdb.set_trace()
    if ax:
        try:
            ax.figure.show()
        except:
            try:
                ax.figure.canvas.draw()
            except:
                pass
    return m
开发者ID:samuelleblanc,项目名称:fp,代码行数:86,代码来源:map_interactive.py


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