在地图上绘制风向图时不显示使用弓形箭头标示

2024-10-01 09:20:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据集是表格数据的形式。我试着用一个仪器绘制沿着特定路径测量的风数据,这个仪器的值和坐标在这个表格数据中给出。数据头如下:

df.head()
>>Lat    Lon      Wind_direction    Air_temp    Water_temp  Wind_speed      
64.1513 -21.935475           106       11.13    11.98        4.8        
64.1515 -21.935418           114       11.59    11.09        9.8        
64.1596 -21.931857           114       11.78    11.58        10.8
64.1596 -21.931857           116       11.59    11.78        10.2   
64.1596 -21.931860           120       11.60    11.82        9.5

我试图按照示例of basemap-rotate vectors来绘制我的数据,但是该图没有生成任何倒钩,并且给出了一个空白图。这是我的密码:

lats1, lons1 = np.array(df.Lat), np.array(df.Lon)
# creating a grid of data points
lats2, lons2 = np.meshgrid(lons1, lats1)
# N-S and E-W components of velocity
u = np.array(df['Wind_speed'] * np.sin(df['Wind_direction'] * np.pi / 180.0))
v = np.array(df['Wind_speed'] * np.cos(df['Wind_direction'] * np.pi / 180.0))
# We have to bring u and v also in the shape of lon and lat to be able to plot them??
u2 = np.ones(lons2.shape) * u
v2 = np.ones(lons2.shape) * v

#rotating the wind vectors
u2_rot, v2_rot, x2, y2 = map.rotate_vector(u2, v2, lons2, lats2, returnxy=True)
fig = plt.figure(figsize=(8,15), dpi=100)
# generating the map
m = Basemap(projection='lcc', resolution='l', llcrnrlat=63, 
urcrnrlat=68,llcrnrlon=-30, urcrnrlon=-20, lat_0=65.25, lon_0=-29.2)
# plotting barbs
# zorder used so that continents don't overlay barbs
m.barbs(x2, y2, u2_rot, v2_rot, pivot='middle', barbcolor='#ff7777', zorder=100)
m.fillcontinents(color='coral',lake_color='aqua')
m.drawmapboundary(fill_color="#DDEEFF")
m.drawcoastlines()

我得到的只是地图上的大陆和海岸线。请指出我在绘制它们时犯了什么概念上的错误。你知道吗


Tags: andofto数据dfnp绘制array