如何设置千米标记?

时间:2018-05-20 15:57:11

标签: python matplotlib-basemap scatter

我想包围某一点。圆的半径需要为5公里,但如何设置我的标记以使圆圈在地图上5公里?

enter image description here

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap

width, height = 400000, 320000
ax=plt.figure(figsize=(20,10))

lonA =[2.631547,2.861595,2.931014]
latA =[51.120983,51.209122,51.238868]

m= Basemap(width=width,height=height,projection='lcc',
        resolution='h',lat_0=52.35,lon_0=4.5)

m.drawmapboundary(fill_color='turquoise')
m.fillcontinents(color='white',lake_color='aqua')
m.drawcountries(linestyle='--')

scatter2=m.scatter([], [], s=100, c='white', marker='o', label = 'Aurelia aurita', zorder=3, alpha=0.5,  edgecolor='steelblue')
z,a = m(lonA[0:3], latA[0:3])
scatter2.set_offsets(np.c_[z,a])

plt.show()

1 个答案:

答案 0 :(得分:0)

要以地图单位(米)绘制具有指定半径的圆,首先,我创建一个函数(genCircle2),它接受圆的输入参数并返回沿该圆的周长的点阵列。在下面的代码中,命令m(lon,lat)用于计算(mx,my)以米为单位的地图投影坐标。 命令genCircle2(cx=mx, cy=my, rad=5000.)计算圆绘图的点数。这是工作代码。

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap

def genCircle2(cx=0, cy=0, rad=1):
    """Generate points along perimeters of a circle"""
    points = []
    segs = 20
    for ea in range(segs+1):
        xi = cx + rad*np.cos(ea*2.*np.pi/segs)
        yi = cy + rad*np.sin(ea*2.*np.pi/segs)
        points.append([xi,yi])
    return np.array(points)

width, height = 400000, 320000
ax = plt.figure(figsize=(12,10))

# long, lat
lonA = [2.631547, 2.861595, 2.931014]
latA = [51.120983, 51.209122, 51.238868]

# accompanying attributes, colors and ...
clrs = ['r', 'g', 'b']

m = Basemap(width=width, height=height, projection='lcc', \
        resolution='i', lat_0=52.35, lon_0=4.5)

m.drawmapboundary(fill_color='turquoise')
m.fillcontinents(color='white', lake_color='aqua')
m.drawcountries(linestyle='--')

# plot circles at points defined by (lonA,latA)
for lon,lat,clr in zip(lonA, latA, clrs):
    mx,my = m(lon,lat)                            # get map coordinates from (lon,lat)
    cclpnts = genCircle2(cx=mx, cy=my, rad=5000.) # get points along circle's perimeter
    m.plot(cclpnts[:,0], cclpnts[:,1], \
               label='Aurelia aurita', color=clr, \
               linewidth=0.75)           # plot circle

plt.show()

结果图:

enter image description here