底图箭头箭头未显示在地图上

时间:2017-03-06 18:30:39

标签: python plot matplotlib-basemap

我有一个方向的全球数据集,我试图用一个颤动图来展示世界的一小部分。箭头不会在图上显示 - 只是每个数据点的点。我的代码如下图所示。我怎样才能显示箭头? 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 个答案:

答案 0 :(得分:1)

添加

scale=10
进入箭袋功能已经解决了我的问题。