2017-05-22 76 views

回答

0

您可以使用底圖而不指定地圖的投影和座標來讀取shapefile。人們可以例如採取從here國家的形狀。

實施例在地圖一個瑞士:

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

m = Basemap() 

fn = r"ne_10m_admin_0_countries\ne_10m_admin_0_countries" 
m.readshapefile(fn, 'shf', drawbounds = False) 

def draw_country(country, ax=None,**kwargs): 
    if ax == None: ax=plt.gca() 
    for info, shape in zip(m.shf_info, m.shf): 
     if info['NAME'] == country: 
      s = np.array(shape) 
      ax.plot(s[:,0], s[:,1], alpha=0) 
      p= Polygon(s, **kwargs) 
      ax.add_artist(p) 


fig, ax = plt.subplots() 
ax.set_aspect("equal") 
draw_country("Switzerland",fill=True, facecolor= "crimson", edgecolor='none', alpha=0.7) 
# try with other contries like 'Ireland', "Venezuela" etc 
plt.show() 

enter image description here

的缺點當然是在不指定所述投影,國形狀可能不是我們從通常的映射用於。

對於在具有圖例的地圖上標繪國家,請參閱this question

相關問題