目录

上一个主题

9.4. 使用数据

下一个主题

9.6. 自定义色彩映射

>>> from helper import info; info()
页面更新时间: 2021-08-04 20:32:29
运行环境:
     Linux发行版本: Debian GNU/Linux 11 (bullseye)
     操作系统内核: Linux-5.10.0-8-amd64-x86_64-with-glibc2.31
     Python版本: 3.9.2

9.5. 球面距离案例

>>> %matplotlib inline
>>> import warnings
>>> warnings.filterwarnings('ignore')
>>> import os
>>> from mpl_toolkits.basemap import Basemap
>>> import matplotlib.pyplot as plt
>>> import numpy as np

9.5.1. 代码

>>> my_map = Basemap(projection='merc', lat_0=38, lon_0=89,
>>>                  resolution='h', area_thresh=0.1,
>>>                  llcrnrlon=58, llcrnrlat=10,
>>>                  urcrnrlon=143, urcrnrlat=55)
>>>
>>> my_map.drawcoastlines()
>>> # my_map.drawcountries()
>>> my_map.fillcontinents(color='lightblue')
>>> my_map.drawmapboundary()
>>>
>>>
>>>
>>> lons = [125.352841, 87.6568,  73.052705]
>>> lats = [43.903566,43.830036, 33.705168]
>>> x, y = my_map(lons, lats)
>>>
>>> labels = ['Changchun', 'Urumqi', 'Islamabad']
>>> x_offsets = [250000] *3
>>> y_offsets = [200000] * 3
>>>
>>>
>>> # x, y = map(lons, lats)
>>>
>>> # my_map.plot(x, y, marker=None,color='r')
>>>
>>> my_map.plot(x, y, 'bo', markersize=10)
>>>
>>> my_map.drawgreatcircle(125.352841, 43.903566, 87.6568, 43.830036, linewidth=2, color='c')
>>> my_map.drawgreatcircle( 87.6568, 43.830036,73.052705,  33.705168, linewidth=2, color='c')
>>>
>>> for label, xpt, ypt, x_offset, y_offset in zip(labels, x, y, x_offsets, y_offsets):
>>>     plt.text(xpt + x_offset, ypt + y_offset, label, color='r')
>>>
>>> plt.show()
_images/basemap-demo_4_0.png