Excellent, thank you. That works for both quiver and barb.
In regards to the shape that has to do with the netcdf file, wind direction
variable also has lat and lon. I ended up needing to slice so I could skip a
few points otherwise there was too many arrows on the map.
Below is the code that worked in case someone else needs help.
Thanks again

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'][20,0::5,0::5]
LAT=ncfile.variables['latitude'][0::5]
LON=ncfile.variables['longitude'][0::5]
TIME=ncfile.variables['time'][20]
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))
u=1*N.sin(WDIR)
v=1*N.cos(WDIR)
map.quiver(x,y,u, v)

#  otherwise use the barb tool - map.barbs(x,y,u, v)

plt.title('Wind Direction')
plt.show()


On Wed, Oct 5, 2011 at 2:00 PM, Ethan Gutmann <ethan.gutm...@gmail.com>wrote:

> Anon,
> I don't know the quiver routine, but u and v are usually vectors for the
> wind speed in the east-west and north south directions.  As such they should
> not be equal to lat and lon (*10), as you are doing, but rather should be
> windspeed * sin(direction)  and windspeed*cos(direction).  If you don't have
> windspeed or want them all to be the same size arrows, just substitute 1 for
> windspeed (or 10 if you want longer arrows)
>
> You shouldn't have to "set" north,south,east,west, etc.  generally North is
> 0, South is 180, etc, so that should all be assigned already.
>
> It also looks like you have an array size mis-match, can you print
> LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon
> variables also need to be subset to [-50]?
>
> hope this helps,
> Ethan
>
> On Oct 4, 2011, at 5:58 PM, questions anon wrote:
>
> 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=10*x
> v=10*y
> 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 <module>
>     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 <efir...@hawaii.edu> wrote:
>
>> On 10/03/2011 03:00 PM, Benjamin Root wrote:
>> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon <
>> questions.a...@gmail.com
>> > <mailto:questions.a...@gmail.com>> 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
>>
>> There is also quiver, both in matplotlib and in basemap.  See the
>> quiver_demo.py and barb_demo.py in the basemap examples directory.
>>
>> Eric
>>
>> >
>> >
>> >
>> >
>> ------------------------------------------------------------------------------
>> > All the data continuously generated in your IT infrastructure contains a
>> > definitive record of customers, application performance, security
>> > threats, fraudulent activity and more. Splunk takes this data and makes
>> > sense of it. Business sense. IT sense. Common sense.
>> > http://p.sf.net/sfu/splunk-d2dcopy1
>> >
>> >
>> >
>> > _______________________________________________
>> > Matplotlib-users mailing list
>> > Matplotlib-users@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>>
>> ------------------------------------------------------------------------------
>> All the data continuously generated in your IT infrastructure contains a
>> definitive record of customers, application performance, security
>> threats, fraudulent activity and more. Splunk takes this data and makes
>> sense of it. Business sense. IT sense. Common sense.
>> http://p.sf.net/sfu/splunk-d2dcopy1
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
>
> http://p.sf.net/sfu/splunk-d2dcopy1_______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to