Anaconda 5.0.0 JupyterLab 0.27.0 中使用 matplotlib basemap 绘制世界地图

准备环境

安全的安装Anaconda3 5.0.0 Windows x86_64

http://blog.csdn.net/hu_zhenghui/article/details/78154684

Anaconda 5.0.0 JupyterLab 0.27.0 中配置多Python环境支持

http://blog.csdn.net/hu_zhenghui/article/details/78163081

正式开始

Python 中最常用的绘图库是 matplotlibAnaconda 5.0.0 中可以很方便的安装 matplotlibmatplotlib 的默认安装并不支持绘制地图,需要额外安装 basemap ,在 Anaconda 5.0.0 中搜索 basemap 可以找到,但是安装的时候会出现如图所示警告。

从警告中可以看到,Anaconda 5.0.0 的默认环境的 Python 的版本是 3.6,而 basemap 依赖于 numpy 1.10 依赖于 python 2.7,为此,需要在 Anaconda 5.0.0 中创建一个 Python 2.7 版本的环境,单击 Create 按钮,出现 Create new environment 对话框,在 Name 文本框中输入 Python27,在 Packages 中选择 Python,在右侧的下拉列表框中选择 2.7,如图所示。

创建后的环境,并不能直接在 JupyterLab 0.27.0 中使用,需要参考前面的文章安装 ipykernel

安装成功后,运行 JupyterLab 0.27.0 ,在 Launcher 中可以看到 Python27,运行如下代码,可以看到版本号。

import sys
sys.version
'2.7.13 |Continuum Analytics, Inc.| (default, May 11 2017, 13:17:26) [MSC v.1500 64 bit (AMD64)]'

Anaconda 5.0.0 中,为 Python 2.7 环境添加 basemap

导入 matplotlib.pyplot

import matplotlib.pyplot

导入 mpl_toolkits.basemap

import mpl_toolkits.basemap

创建一个地图, mpl_toolkits.basemap.Basemap 的参数较多,详见本文末尾。

basemap = mpl_toolkits.basemap.Basemap()

在地图上绘制海岸线

basemap.drawcoastlines()
<matplotlib.collections.LineCollection at 0x9efee48>

绘制海岸线函数可以设定线宽、线型、颜色、抗锯齿等参数。

basemap.drawcoastlines?

    Signature: basemap.drawcoastlines(linewidth=1.0, linestyle='solid', color='k', antialiased=1, ax=None, zorder=None)
    Docstring:
    Draw coastlines.
    
    .. tabularcolumns:: |l|L|
    
    ==============   ====================================================
    Keyword          Description
    ==============   ====================================================
    linewidth        coastline width (default 1.)
    linestyle        coastline linestyle (default solid)
    color            coastline color (default black)
    antialiased      antialiasing switch for coastlines (default True).
    ax               axes instance (overrides default axes instance)
    zorder           sets the zorder for the coastlines (if not specified,
                     uses default zorder for
                     matplotlib.patches.LineCollections).
    ==============   ====================================================
    
    returns a matplotlib.patches.LineCollection object.
    File:      c:\users\huzh\appdata\local\conda\conda\envs\python27\lib\site-packages\mpl_toolkits\basemap\__init__.py
    Type:      instancemethod
    

保存图片

matplotlib.pyplot.savefig('world.png')

就得到了一张世界地图

mpl_toolkits.basemap.Basemap?

    Init signature: mpl_toolkits.basemap.Basemap(self, llcrnrlon=None, llcrnrlat=None, urcrnrlon=None, urcrnrlat=None, llcrnrx=None, llcrnry=None, urcrnrx=None, urcrnry=None, width=None, height=None, projection='cyl', resolution='c', area_thresh=None, rsphere=6370997.0, ellps=None, lat_ts=None, lat_1=None, lat_2=None, lat_0=None, lon_0=None, lon_1=None, lon_2=None, o_lon_p=None, o_lat_p=None, k_0=None, no_rot=False, suppress_ticks=True, satellite_height=35786000, boundinglat=None, fix_aspect=True, anchor='C', celestial=False, round=False, epsg=None, ax=None)
    Docstring:      <no docstring>
    Init docstring:
    Sets up a basemap with specified map projection.
    and creates the coastline data structures in map projection
    coordinates.
    
    Calling a Basemap class instance with the arguments lon, lat will
    convert lon/lat (in degrees) to x/y map projection coordinates
    (in meters). The inverse transformation is done if the optional keyword
    inverse is set to True.
    
    The desired projection is set with the projection keyword. Default is cyl.
    Supported values for the projection keyword are:
    
    ==============   ====================================================
    Value            Description
    ==============   ====================================================
    cea              Cylindrical Equal Area                  
    mbtfpq           McBryde-Thomas Flat-Polar Quartic       
    aeqd             Azimuthal Equidistant                   
    sinu             Sinusoidal                              
    poly             Polyconic                               
    omerc            Oblique Mercator                        
    gnom             Gnomonic                                
    moll             Mollweide                               
    lcc              Lambert Conformal                       
    tmerc            Transverse Mercator                     
    nplaea           North-Polar Lambert Azimuthal           
    gall             Gall Stereographic Cylindrical          
    npaeqd           North-Polar Azimuthal Equidistant       
    mill             Miller Cylindrical                      
    merc             Mercator                                
    stere            Stereographic                           
    eqdc             Equidistant Conic                       
    rotpole          Rotated Pole                            
    cyl              Cylindrical Equidistant                 
    npstere          North-Polar Stereographic               
    spstere          South-Polar Stereographic               
    hammer           Hammer                                  
    geos             Geostationary                           
    nsper            Near-Sided Perspective                  
    eck4             Eckert IV                               
    aea              Albers Equal Area                       
    kav7             Kavrayskiy VII                          
    spaeqd           South-Polar Azimuthal Equidistant       
    ortho            Orthographic                            
    cass             Cassini-Soldner                         
    vandg            van der Grinten                         
    laea             Lambert Azimuthal Equal Area            
    splaea           South-Polar Lambert Azimuthal           
    robin            Robinson                                
    
    ==============   ====================================================
    
    For most map projections, the map projection region can either be
    specified by setting these keywords:
    
    .. tabularcolumns:: |l|L|
    
    ==============   ====================================================
    Keyword          Description
    ==============   ====================================================
    llcrnrlon        longitude of lower left hand corner of the desired map
                     domain (degrees).
    llcrnrlat        latitude of lower left hand corner of the desired map
                     domain (degrees).
    urcrnrlon        longitude of upper right hand corner of the desired map
                     domain (degrees).
    urcrnrlat        latitude of upper right hand corner of the desired map
                     domain (degrees).
    ==============   ====================================================
    
    or these
    
    .. tabularcolumns:: |l|L|
    
    ==============   ====================================================
    Keyword          Description
    ==============   ====================================================
    width            width of desired map domain in projection coordinates
                     (meters).
    height           height of desired map domain in projection coordinates
                     (meters).
    lon_0            center of desired map domain (in degrees).
    lat_0            center of desired map domain (in degrees).
    ==============   ====================================================
    
    For sinu, mollhammernpsterespsterenplaeasplaea,
    npaeqd, spaeqdrobineck4kav7, or mbtfpq, the values of
    llcrnrlon, llcrnrlat, urcrnrlon, urcrnrlat, width and height are ignored
    (because either they are computed internally, or entire globe is
    always plotted).
    
    For the cylindrical projections (cyl, mercmillcea  and gall),
    the default is to use
    llcrnrlon=-180,llcrnrlat=-90, urcrnrlon=180 and urcrnrlat=90). For all other
    projections except ortho, geos and nsper, either the lat/lon values of the
    corners or width and height must be specified by the user.
    
    For ortho, geos and nsper, the lat/lon values of the corners may be specified,
    or the x/y values of the corners (llcrnrx,llcrnry,urcrnrx,urcrnry) in the
    coordinate system of the global projection (with x=0,y=0 at the center
    of the global projection).  If the corners are not specified,
    the entire globe is plotted.
    
    For rotpole, the lat/lon values of the corners on the unrotated sphere
    may be provided as llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat, or the lat/lon
    values of the corners on the rotated sphere can be given as
    llcrnrx,llcrnry,urcrnrx,urcrnry.
    
    Other keyword arguments:
    
    .. tabularcolumns:: |l|L|
    
    ==============   ====================================================
    Keyword          Description
    ==============   ====================================================
    resolution       resolution of boundary database to use. Can be c
                     (crude), l (low), i (intermediate), h
                     (high), f (full) or None.
                     If None, no boundary data will be read in (and
                     class methods such as drawcoastlines will raise an
                     if invoked).
                     Resolution drops off by roughly 80% between datasets.
                     Higher res datasets are much slower to draw.
                     Default c. Coastline data is from the GSHHS
                     (http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html).
                     State, country and river datasets from the Generic
                     Mapping Tools (http://gmt.soest.hawaii.edu).
    area_thresh      coastline or lake with an area smaller than
                     area_thresh in km^2 will not be plotted.
                     Default 10000,1000,100,10,1 for resolution
                     c, lihf.
    rsphere          radius of the sphere used to define map projection
                     (default 6370997 meters, close to the arithmetic mean
                     radius of the earth). If given as a sequence, the
                     first two elements are interpreted as the radii
                     of the major and minor axes of an ellipsoid.
                     Note: sometimes an ellipsoid is specified by the
                     major axis and an inverse flattening parameter (if).
                     The minor axis (b) can be computed from the major
                     axis (a) and the inverse flattening parameter using
                     the formula if = a/(a-b).
    ellps            string describing ellipsoid ('GRS80' or 'WGS84',
                     for example). If both rsphere and ellps are given,
                     rsphere is ignored. Default None. See pyproj.pj_ellps
                     for allowed values.
    suppress_ticks   suppress automatic drawing of axis ticks and labels
                     in map projection coordinates.  Default False,
                     so parallels and meridians can be labelled instead.
                     If parallel or meridian labelling is requested
                     (using drawparallels and drawmeridians methods),
                     automatic tick labelling will be supressed even if
                     suppress_ticks=False.  suppress_ticks=False
                     is useful if you want to use your own custom tick
                     formatter, or  if you want to let matplotlib label
                     the axes in meters using map projection
                     coordinates.
    fix_aspect       fix aspect ratio of plot to match aspect ratio
                     of map projection region (default True).
    anchor           determines how map is placed in axes rectangle
                     (passed to axes.set_aspect). Default is C,
                     which means map is centered.
                     Allowed values are
                     C, SWSSEENE,
                     N, NW, and W.
    celestial        use astronomical conventions for longitude (i.e.
                     negative longitudes to the east of 0). Default False.
                     Implies resolution=None.
    ax               set default axes instance
                     (default None - matplotlib.pyplot.gca() may be used
                     to get the current axes instance).
                     If you don not want matplotlib.pyplot to be imported,
                     you can either set this to a pre-defined axes
                     instance, or use the ax keyword in each Basemap
                     method call that does drawing. In the first case,
                     all Basemap method calls will draw to the same axes
                     instance.  In the second case, you can draw to
                     different axes with the same Basemap instance.
                     You can also use the ax keyword in individual
                     method calls to selectively override the default
                     axes instance.
    ==============   ====================================================
    
    The following keywords are map projection parameters which all default to
    None.  Not all parameters are used by all projections, some are ignored.
    The module variable projection_params is a dictionary which
    lists which parameters apply to which projections.
    
    .. tabularcolumns:: |l|L|
    
    ================ ====================================================
    Keyword          Description
    ================ ====================================================
    lat_ts           latitude of true scale. Optional for stereographic,
                     cylindrical equal area and mercator projections.
                     default is lat_0 for stereographic projection.
                     default is 0 for mercator and cylindrical equal area
                     projections.
    lat_1            first standard parallel for lambert conformal,
                     albers equal area and equidistant conic.
                     Latitude of one of the two points on the projection
                     centerline for oblique mercator. If lat_1 is not given, but
                     lat_0 is, lat_1 is set to lat_0 for lambert
                     conformal, albers equal area and equidistant conic.
    lat_2            second standard parallel for lambert conformal,
                     albers equal area and equidistant conic.
                     Latitude of one of the two points on the projection
                     centerline for oblique mercator. If lat_2 is not
                     given it is set to lat_1 for lambert conformal,
                     albers equal area and equidistant conic.
    lon_1            Longitude of one of the two points on the projection
                     centerline for oblique mercator.
    lon_2            Longitude of one of the two points on the projection
                     centerline for oblique mercator.
    k_0              Scale factor at natural origin (used
                     by 'tmerc', 'omerc', 'stere' and 'lcc').
    no_rot           only used by oblique mercator.
                     If set to True, the map projection coordinates will
                     not be rotated to true North.  Default is False
                     (projection coordinates are automatically rotated).
    lat_0            central latitude (y-axis origin) - used by all
                     projections.
    lon_0            central meridian (x-axis origin) - used by all
                     projections.
    boundinglat      bounding latitude for pole-centered projections
                     (npstere,spstere,nplaea,splaea,npaeqd,spaeqd).
                     These projections are square regions centered
                     on the north or south pole.
                     The longitude lon_0 is at 6-o'clock, and the
                     latitude circle boundinglat is tangent to the edge
                     of the map at lon_0.
    round            cut off pole-centered projection at boundinglat
                     (so plot is a circle instead of a square). Only
                     relevant for npstere,spstere,nplaea,splaea,npaeqd
                     or spaeqd projections. Default False.
    satellite_height height of satellite (in m) above equator -
                     only relevant for geostationary
                     and near-sided perspective (geos or nsper)
                     projections. Default 35,786 km.
    ================ ====================================================
    
    Useful instance variables:
    
    .. tabularcolumns:: |l|L|
    
    ================ ====================================================
    Variable Name    Description
    ================ ====================================================
    projection       map projection. Print the module variable
                     supported_projections to see a list of allowed
                     values.
    epsg             EPSG code defining projection (see
                     http://spatialreference.org for a list of
                     EPSG codes and their definitions).
    aspect           map aspect ratio
                     (size of y dimension / size of x dimension).
    llcrnrlon        longitude of lower left hand corner of the
                     selected map domain.
    llcrnrlat        latitude of lower left hand corner of the
                     selected map domain.
    urcrnrlon        longitude of upper right hand corner of the
                     selected map domain.
    urcrnrlat        latitude of upper right hand corner of the
                     selected map domain.
    llcrnrx          x value of lower left hand corner of the
                     selected map domain in map projection coordinates.
    llcrnry          y value of lower left hand corner of the
                     selected map domain in map projection coordinates.
    urcrnrx          x value of upper right hand corner of the
                     selected map domain in map projection coordinates.
    urcrnry          y value of upper right hand corner of the
                     selected map domain in map projection coordinates.
    rmajor           equatorial radius of ellipsoid used (in meters).
    rminor           polar radius of ellipsoid used (in meters).
    resolution       resolution of boundary dataset being used (c
                     for crude, l for low, etc.).
                     If None, no boundary dataset is associated with the
                     Basemap instance.
    proj4string      the string describing the map projection that is
                     used by PROJ.4.
    ================ ====================================================
    
    **Converting from Geographic (lon/lat) to Map Projection (x/y) Coordinates**
    
    Calling a Basemap class instance with the arguments lon, lat will
    convert lon/lat (in degrees) to x/y map projection
    coordinates (in meters).  If optional keyword inverse is
    True (default is False), the inverse transformation from x/y
    to lon/lat is performed.
    
    For cylindrical equidistant projection (cyl), this
    does nothing (i.e. x,y == lon,lat).
    
    For non-cylindrical projections, the inverse transformation
    always returns longitudes between -180 and 180 degrees. For
    cylindrical projections (self.projection == cyl, mill,
    cea, gall or merc)
    the inverse transformation will return 

Anaconda 5.0.0 JupyterLab 0.27.0 中使用 matplotlib basemap 绘制世界地图相关推荐

  1. anaconda新建python2环境安装不了jupyterlab_Anaconda 5.0.0 JupyterLab 0.27.0 中配置多Python环境支持...

    Anaconda 5.0.0 JupyterLab 0.27.0 中配置多Python环境支持 概述 Anaconda 5.0.0 中自带了 JupyterLab 0.27.0 版本,这是 Anaco ...

  2. 【我的Android进阶之旅】解决SDK升级到27.0.3遇到的GLIBC_2.14 not found、no acceptable C compiler found in $PATH等问题...

    一.问题一:Failed to find Build Tools revision 27.0.3 1.1.问题描述 最近公司的Android项目都要进行SDK升级,目前在本地编译的时候将SDK升级到了 ...

  3. healthd: battery l=1 v=0 t=27.0 h=2 st=1 chg=a 注释方法

    如果想去掉这个串口打印healthd: battery l=1 v=0 t=27.0 h=2 st=1 chg=a可以按照下面的方法. 去掉它的原因是,在使用串口命令时它如果总是打印,岂不很烦,所以去 ...

  4. annotations' in project ':test'. Resolved versions for app (26.1.0) and test app (27.1.1) differ

    报错如下: Error:Execution failed for task ':test:preDebugAndroidTestBuild'. > Conflict with dependenc ...

  5. 智能实验室-杀马(Defendio) 4.27.0.951

    怎样获取最新版本? □智能更新: 打开杀马(Defendio),按F9键,或者点左边的服务->智能更新 □全新下载: 杀马(Defendio):http://files.cnblogs.com/ ...

  6. 利用python安装opencv_科学网—Anaconda Python PyCharm PyQT5 OpenCV PyTorch TF2.0 安装指南 - 张重生的博文...

    Anaconda Python PyCharm PyQT5 OpenCV PyTorch TF2.0 安装指南与资料汇总 (用Anaconda配置Python集成开发环境,含Python3, PyQT ...

  7. repo sync 更新源码 android-12.0.0_r34, fatal: 不能重置索引文件至版本 ‘v2.27^0‘。

    文章目录 1. 问题描述 2. 错误日志 2.1 操作过程 2.2 错误分析 3.解决办法 4. 最后 1. 问题描述 AOSP 12的源码两月没有更新了,今日对其做repo sync动作,并切换到新 ...

  8. fatal: unable to access ‘‘: Failed to connect to 27.0.0.1 port 7890 after 2097 ms:Connection

    今天在使用 git pull 的时候发生了这个错误 fatal: unable to access '': Failed to connect to 27.0.0.1 port 7890 after ...

  9. android SDK buid tools 27.0.3版本离线下载

    哈哈,没错,我就是这么乐于助人~ 免费分享 buid tools 27.0.3的下载地址,我自己也是花了5个积分买的 可以点击下面的链接在百度云盘下载哦~ 链接:https://pan.baidu.c ...

最新文章

  1. bash: vue: command not found
  2. 10行代码理解Java锁消除
  3. Python中装饰器的理解和实现
  4. php 判断是否文件,利用PHP判断文件是否为图片的方法总结
  5. GitHub项目管理维护实用教程
  6. selenium-入门与安装-0223
  7. 【华为云技术分享】初识MySQL隔离级别
  8. js 将内部函数变成全局函数_js中三种作用域详解(全局,函数,块级)
  9. 程序员过关斩将——搞定秒杀,只需要这几步!!
  10. 将Excel的数据导入DataGridView中[原创]
  11. python ant_python3.7.1ant+TKinter在Tkin中显示来自ANT+设备的实时数据
  12. 【交通标志识别】基于matlab SIFT交通标志识别【含Matlab源码 717期】
  13. 微软vc运行库地址VC9VC11
  14. cdr多页面排版_CDR文字排版实战图文教程,CorelDRAW文字排版有哪些技巧?
  15. SEO整体优化有哪些操作步骤
  16. Windows 性能监视器API
  17. 应用多开,定位,机型伪装这都有
  18. Towards Adversarial Attack on Vision-Language Pre-training Models
  19. Runtime.getRuntime.exec()执行linux脚本导致程序卡死问题
  20. PointFusion: Deep Sensor Fusion for 3D Bounding Box Estimation

热门文章

  1. Acrel-3000电能管理系统 在陕西煤业化工建设(集团)基地办公楼 项目的应用-安科瑞苏月婷
  2. 企业微信应用设置可信域名_企业微信应用变更域名,可信域名只能设置一个导致原有推送的模板消息(旧域名)直接提示需使用应用可信域名...
  3. 基于MVS的三维重建算法学习笔记(一)— MVS三维重建概述与OpenMVS开源框架配置
  4. 计算机毕业设计ssm家猪智能饲养管理系统wt2ah系统+程序+源码+lw+远程部署
  5. OpenCV从入门到精通——边缘检测算法Canny
  6. 微服务之SpringCloud服务调用
  7. 提高软件测试效率的方法探讨
  8. java web相册_javaWEB之-----------简单的相册管理
  9. java微信公众平台开发接口_微信公众平台API的Java通讯实现
  10. 淘宝层级改版,五力模型上线!