2017-03-06 151 views
0

我有一個全局數據集的方向,我試圖使用箭頭圖來顯示世界的一小部分。箭頭沒有顯示在圖上 - 只是在每個數據點上都有點。我的代碼如下圖所示。我怎樣才能讓箭頭顯示? Quiver plot - no arrows底圖上箭頭箭頭沒有顯示在地圖上

from netCDF4 import Dataset 
import datetime 
from mpl_toolkits.basemap import Basemap 
import matplotlib.pyplot as plt 
import cPickle as pickle 
import numpy as np 

file_name = 'file.nc' 
file2 = Dataset(file_name, mode='r') 

lons2 = file2.variables['lon'][:] 
lats2 = file2.variables['lat'][:] 
times2 = file2.variables['time'][:] 
wind_dir = file2.variables['wind_dir'][:] 

#limits for the plot 
#longitudes 
x1 = 5 
x2 = 7 
#latitudes 
y1 = 41 
y2 = 43.4 

plt.figure() 
map = Basemap(resolution='f',projection='merc',area_thresh = 0.1, llcrnrlat=y1,urcrnrlat=y2,llcrnrlon=x1,urcrnrlon=x2,lat_ts=(x1+x2)/2) 
map.drawcountries(linewidth=0.5) 
map.drawcoastlines(linewidth=0.5) 
map.drawmapboundary(fill_color='aqua') 
map.fillcontinents(color='coral',lake_color='aqua') 

x,y = map(lons2,lats2) 
map.quiver(x,y,np.cos(np.deg2rad(wind_dir)),np.sin(np.deg2rad(wind_dir)),edgecolor='k', facecolor='white', linewidth=.5) 

我還創建了一個顫抖的情節在相關區域(請參見下面的代碼)只是一個點,箭頭繪製。我很困惑,爲什麼這是達到預期的結果,當上面的代碼不是。 (見圖) enter image description here

target_lat = 43 
target_lon = 6.35 
diff = 1000 
for i in range(3264): 
    for j in range(82): 
     lat = lats2[i,j] 
     lon = lons2[i,j] 
     lat_d = target_lat - lat 
     lon_d = target_lon - lon 
     diff_n = np.sqrt(lat_d**2 + lon_d**2) 
     if diff_n < diff: 
      diff = diff_n 
      time_ix = i 
      space_ix = j 

x_t, y_t = map(lons2[time_ix,space_ix],lats2[time_ix,space_ix]) 
map.quiver(x_t,y_t,np.cos(np.deg2rad(wind_dir[time_ix,space_ix])),np.sin(np.deg2rad(wind_dir[time_ix,space_ix])),edgecolor='k', facec`olor='white', linewidth=.5) 

plt.show() 
file2.close() 

回答

1

添加

scale=10 

進入顫動功能已經解決了我的問題。