zoukankan      html  css  js  c++  java
  • 3d_basemap

    matplotlib之 3D 元素的地图

    mplot3d工具包创建3D地图

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    from mpl_toolkits.basemap import Basemap
    
    map = Basemap()
    fig = plt.figure()
    ax = Axes3D(fig) # 设置3d画布
    
    # 1. 默认情况下轴旋转为一
    
    
    # 2. 设置了轴旋转,以便从z轴观看地图,就像在2D中绘制地图时一样
    """
        ax.azim = 270
        ax.elev =90
        ax.dist = 5
    """
    
    ax.add_collection3d(map.drawcoastlines(linewidth=0.25))
    ax.add_collection3d(map.drawcountries(linewidth=0.35))
    plt.show()
    
    """
        # 备注:
            1. ax 变量是Axes3D 实例, 将所有方法都在此实例中使用,因此需要支持3d操作.
            2. 带注释的块显示了如何旋转生成的地图,从而使视野更好
            3. 要绘制线条,只需要将add_collection3d方法与任何返回 matplotlib.patches.LineCollection
            对象的方法的输出一起使用. 例如 drawcountries
    """
    

    填充多边形 Filling the polygons

    """
        # 1. 地图 的fillcontinents方法不会返回 add_collection3d支持的对象(PolyCollection,LineCollection,PatchCollection) , 而是返回maptplotlib.patches.Polygon对象的列表     
    """
    from matplotlib.collections import PolyCollection
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    from mpl_toolkits.basemap import Basemap
    
    map =Basemap()
    fig = plt.figure()
    ax = Axes3D(fig)
    
    ax.azim =270
    ax.elev =50
    ax.dist = 8
    
    ax.add_collection3d(map.drawcoastlines(linewidth=0.25))
    ax.add_collection3d(map.drawcountries(linewidth=0.35))
    
    polys = []
    
    for polygon in map.landpolygons:
        polys.append(polygon.get_coords())
    
    lc = PolyCollection(polys,edgecolors='black',facecolors='#DDDDDD',closed=False)
    
    ax.add_collection3d(lc)
    plt.show()
    '''
        # 上述 所绘制 海岸线和国家
            1. 创建PolyCollection,需要使用多边形,地图对象将其放置子landpolygons字段中,其中包含多边形,例如国家/地区/其他
            2. 对于每个多边形,可以使用get_coords方法将坐标检索为浮点列表. 因为是geoslib.Polygon独享
            3. 一旦创建坐标列表,便可以构建PoilyCollection
            4. 在行中所做的那样,可以使用add_collection3d 添加PolyCollection
            5. 如果原始多边形是使用fillcontinents,添加的.则matplotlib表示没有将其转换为3d的方法
    '''
    

    添加3d条

    '''
        #  未在其上绘制3d数据,则创建3d地图是没有任何意义的. 还Axes3D类具有绘制3d方法
    '''
    
    import numpy as np
    map = Basemap(llcrnrlon=-20,llcrnrlat=0,urcrnrlon=15,urcrnrlat=50)
    
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.set_axis_off()
    ax.azim=270
    ax.dist=7
    polys =[]
    
    for polygon in map.landpolygons:
        polys.append(polygon.get_coords())
    
    lc = PolyCollection(polys,edgecolors='black',facecolors="#dddddd",closed=False)
    ax.add_collection3d(lc)
    ax.add_collection3d(map.drawcoastlines(linewidth=0.25))
    ax.add_collection3d(map.drawcountries(linewidth=0.35))
    
    lons = np.array([-13.7, -10.8, -13.2, -96.8, -7.99, 7.5, -17.3, -3.7])
    lats = np.array([9.6, 6.3, 8.5, 32.7, 12.5, 8.9, 14.7, 40.39])
    cases = np.array([1971, 7069, 6073, 4, 6, 20, 1, 1])
    deaths = np.array([1192, 2964, 1250, 1, 5, 8, 0, 0])
    places = np.array(['Guinea', 'Liberia', 'Sierra Leone','United States', 'Mali', 'Nigeria', 'Senegal', 'Spain'])
    
    x,y = map(lons,lats)
    ax.bar3d(x,y,np.zeros(len(x)),2,2,deaths,color='r',alpha=0.8)
    
    plt.show()
    
    '''
        # 备注:
            1. 使用set_axis_off方法消除轴
            2. bar3d 需要x,y和z位置. 以及增量x,y和z. 要正确绘制,z位置必须为0,且增量z为最终值
    '''
    
  • 相关阅读:
    Natas Wargame Level 13 Writeup(文件上传漏洞,篡改file signature,Exif)
    Natas Wargame Level 12 Writeup(文件上传漏洞)
    Natas Wargame Level 9 Writeup(bash injection)
    Natas Wargame Level 2 Writeup 与目录泄露(强制访问)
    Natas Wargame Level 3 Writeup 与 robots.txt
    字符编码与文件操作
    python 基本数据类型
    python数据类型内置方法 字符串和列表
    python常用模块
    python数据类型及基本运算符
  • 原文地址:https://www.cnblogs.com/dengz/p/14835580.html
Copyright © 2011-2022 走看看