Basemap在地图上绘制数据(整理自官网)

本文介绍了如何使用Matplotlib的Basemap库绘制地图,包括设置地图投影、绘制海岸线、国家边界等内容,并展示了如何在地图上绘制等高线、图像和其他数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

整理自https://matplotlib.org/basemap/users/examples.html

  • 用到的方法:
  • contour(): draw contour lines.(等高线)
    contourf(): draw filled contours.
    imshow(): draw an image.
    pcolor(): draw a pseudocolor plot.(伪色图)
    pcolormesh(): draw a pseudocolor plot (faster version for regular meshes).
    画一个伪颜色图(对于普通网格来说是更快的版本)。
    plot(): draw lines and/or markers.
    scatter(): draw points with markers.
    quiver(): draw vectors.
    barbs(): draw wind barbs.
    drawgreatcircle(): draw a great circle.
  • drawcoastlines(): draw coastlines.

  • fillcontinents(): 为大陆内部上色。不幸的是,fillmethods并不总是正确的。Matplotlib总是试图填充多边形的内部。在某些情况下,海岸线多边形的内部可能是模糊的,外部可能被填充而不是内部。在这些情况下,推荐的解决方法是使用drawlsmask()方法,使用为陆地和水域指定的不同颜色覆盖图像(见下文)。

  • drawcountries(): draw country boundaries.

  • drawstates(): 划定北美各州界限

  • drawrivers(): draw rivers.

  • drawlsmask(): 绘制高分辨率陆地-海洋掩模作为图像,指定陆地和海洋的颜色。陆海掩模来自GSHHS的海岸线数据,有几种海岸线选项和像素大小可供选择。

  • drawlsmask(land_color=‘0.8’, ocean_color=‘w’, lsmask=None, lsmask_lons=None, lsmask_lats=None, lakes=True, resolution=‘l’, grid=5, **kwargs)

  • bluemarble(): draw a NASA Blue Marble image as a map background.

  • shadedrelief(): draw a shaded relief image as a map background.

  • etopo(): draw an etopo relief image as map background.

  • warpimage(): 使用一个任意的图像作为地图背景。图像必须是全球的,从国际日期变更线向东,南极向北,以经纬线坐标覆盖整个世界。

  • warpimage(image=‘bluemarble’, scale=None, **kwargs)


  • drawmapboundary(color=‘k’, linewidth=1.0, fill_color=None, zorder=None, ax=None)

  • 绘制地图投影区域的边界,可选填充区域的内部。

  • 官方示例:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
# 设置50N, 100W的卫星俯视视角的正射地图投影。
# 使用低分辨率海岸线.
map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# draw lat/lon grid lines every 30 degrees.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))
plt.show()
  • 到此为止已经设置好基本的一个地图了

在这里插入图片描述

  • 接下来上数据
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
x, y = map(lons*180./np.pi, lats*180./np.pi)
# contour data over the map.
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
plt.title('contour lines over filled continent background')
plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值