Thanks for responding. I believe quiver is more appropriate because I am only using wind direction (at this stage) and this results in arrows.
I have had a look at the demos and still do not understand how to plot my degrees in arrows. How do I define which angle is north, south, west, east, etc?
Any suggestions? Thanks
from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
ncfile=Dataset(‘E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc’, ‘r+’, ‘NETCDF4’)
WDIR=ncfile.variables[‘Wind_Dir_SFC’][-50]
LAT=ncfile.variables[‘latitude’][:]
LON=ncfile.variables[‘longitude’][:]
TIME=ncfile.variables[‘time’][-50]
ncfile.close()
map = Basemap(projection=‘merc’,llcrnrlat=-40,urcrnrlat=-33,
llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=LON,LAT
u=10x
v=10y
map.quiver(x,y,u, v, WDIR)
plt.title(‘Wind Direction’)
plt.show()
Traceback (most recent call last):
File “d:/plot_winddirection.py”, line 22, in
map.quiver(x,y,u, v, WDIR)
File “C:\Python27\lib\site-packages\mpl_toolkits\basemap_init_.py”, line 3102, in quiver
ret = ax.quiver(x,y,u,v,*args,**kwargs)
File “C:\Python27\lib\site-packages\matplotlib\axes.py”, line 6320, in quiver
q = mquiver.Quiver(self, *args, **kw)
File “C:\Python27\lib\site-packages\matplotlib\quiver.py”, line 395, in init
self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
File “C:\Python27\lib\site-packages\numpy\core\shape_base.py”, line 270, in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0
On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <efiring@…202…> wrote:
On 10/03/2011 03:00 PM, Benjamin Root wrote:
On Mon, Oct 3, 2011 at 6:51 PM, questions anon <questions.anon@…287… > > > > mailto:questions.anon@...287...> wrote:
Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I
would like to make a plot with all little arrows representing the
wind direction.
Below is the code I am using currently to plot wind direction but am
not sure where/how to add directional arrows.
Thanks
from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
ncfile.close()
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=map(*N.meshgrid(LON,LAT))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()
Would the barb() command do what you want?
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
They aren’t arrows, but they are commonly used in meteorology to plot
windfields.
Cheers,
Ben Root