【发布时间】:2019-11-11 22:18:45
【问题描述】:
我想使用 Python/Matplotlib/Basemap 绘制地图并对位于指定点的给定距离内的圆进行着色,类似于此(由 Great Circle Mapper 生成的地图 - 版权所有 © Karl L. Swartz。 ):
我可以让地图生成如下:
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
# create new figure, axes instances.
fig,ax = plt.subplots()
# setup Mercator map projection.
m = Basemap(
llcrnrlat=47.0,
llcrnrlon=-126.62,
urcrnrlat=50.60,
urcrnrlon=-119.78,
rsphere=(6378137.00,6356752.3142),
resolution='i',
projection='merc',
lat_0=49.290,
lon_0=-123.117,
)
# Latitudes and longitudes of locations of interest
coords = dict()
coords['SEA'] = [47.450, -122.309]
# Plot markers and labels on map
for key in coords:
lon, lat = coords[key]
x,y = m(lat, lon)
m.plot(x, y, 'bo', markersize=5)
plt.text(x+10000, y+5000, key, color='k')
# Draw in coastlines
m.drawcoastlines()
m.fillcontinents()
m.fillcontinents(color='grey',lake_color='aqua')
m.drawmapboundary(fill_color='aqua')
plt.show()
生成地图:
现在我想在指定点周围创建一个大圆圈,例如顶部地图。
我的尝试是一个函数,它接受地图对象、中心坐标对和距离,并创建两条曲线,然后在它们之间着色,类似于:
def shaded_great_circle(map_, lat_0, lon_0, dist=100, alpha=0.2): # dist specified in nautical miles
dist = dist * 1852 # Convert distance to nautical miles
lat = np.linspace(lat_0-dist/2, lat_0+dist/2,50)
lon = # Somehow find these points
# Create curve for longitudes above lon_0
# Create curve for longitudes below lon_0
# Shade region between above two curves
我已经评论了我想做的事情,但不知道该怎么做。
我尝试了几种方法来做到这一点,但让我感到困惑的是,地图的所有输入都是以度为单位的坐标,而我想指定长度点,并将其转换为纬度/经度点阴谋。我认为这与以度数为单位的纬度/经度数据与地图投影坐标有关。
任何朝着正确方向的轻推将不胜感激 谢谢
【问题讨论】:
标签: python matplotlib matplotlib-basemap