2017-05-22 9 views

答えて

0

シェイプファイルを読み込むためにマップの投影と座標を指定せずに、ベースマップを使用することができます。例えば、国の形を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

関連する問題