# Example of plotting vectors over magnitude

**URL:** <https://forum.generic-mapping-tools.org/t/example-of-plotting-vectors-over-magnitude/2288>\
**Category:** PyGMT Q&A\
**Created:** [November 10, 2021, 4:42pm UTC](https://forum.generic-mapping-tools.org/t/example-of-plotting-vectors-over-magnitude/2288 "2021-11-10T16:42:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjo](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/sjo/32/1743_2.png) [@sjo](https://forum.generic-mapping-tools.org/u/sjo)\
**Post date:** [November 10, 2021, 4:42pm UTC](https://forum.generic-mapping-tools.org/t/example-of-plotting-vectors-over-magnitude/2288/1 "2021-11-10T16:42:14Z")

</div>

HI,  
I was looking for an example using pygmt plotting ocean current vectors over the speed which is filled in the background from a NetCDF file. For example the HYCOM current vectors available from the below location which can be loaded to python memory using the below commands. And normal quiver plot can be made . But I wanted to use pygmt for this purpose, please direct me to an implemented example if possible.

from netCDF4 import Dataset as nc  
nf=nc(“[https://tds.hycom.org/thredds/dodsC/GLBv0.08/expt\_56.3](https://tds.hycom.org/thredds/dodsC/GLBv0.08/expt_56.3)”)  
lat=nf.variables[‘lat’][:]  
lon=nf.variables[‘lon’][:]  
#nf.variables[‘water\_u’].shape  
idx1 = (np.abs(lat - 0)).argmin()  
idx2 = (np.abs(lat - 25)).argmin()  
idx3=(np.abs(lon-65)).argmin()  
idx4=(np.abs(lon-90)).argmin()  
[lat[idx1],lat[idx2],lon[idx3],lon[idx4]]  
uvel=nf.variables[‘water\_u’][1,0,idx1:idx2,idx3:idx4]  
vvel=nf.variables[‘water\_v’][1,0,idx1:idx2,idx3:idx4]  
lat1=nf.variables[‘lat’][idx1:idx2]  
lon1=nf.variables[‘lon’][idx3:idx4]  
spd=np.sqrt(np.square(uvel)+np.square(vvel))  
x,y=np.meshgrid(lon1,lat1)  
plt.contourf(x,y,spd,50)  
plt.quiver(x,y,uvel,vvel,scale=20)

---

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [November 10, 2021, 6:27pm UTC](https://forum.generic-mapping-tools.org/t/example-of-plotting-vectors-over-magnitude/2288/2 "2021-11-10T18:27:29Z")

</div>

Hi @sjo, try having a look at [Plot wind vectors from a XArray DataArray](https://flint.soest.hawaii.edu/t/plot-wind-vectors-from-a-xarray-dataarray/1002/3) or [https://www.pygmt.org/v0.5.0/gallery/seismology/velo\_arrow\_ellipse.html](https://www.pygmt.org/v0.5.0/gallery/seismology/velo_arrow_ellipse.html). You may also want to look at [https://www.pygmt.org/v0.5.0/gallery/images/contours.html](https://www.pygmt.org/v0.5.0/gallery/images/contours.html) for the contour part. Give those a try first and we can help out with any details later.

---

<div class="post-metadata">

**Author:** ![sjo](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/sjo/32/1743_2.png) [@sjo](https://forum.generic-mapping-tools.org/u/sjo)\
**Post date:** [November 12, 2021, 6:55am UTC](https://forum.generic-mapping-tools.org/t/example-of-plotting-vectors-over-magnitude/2288/3 "2021-11-12T06:55:48Z")

</div>

Thank you weiji14,  
With the tips, I could make the plots, but only after making the data as x,y,z triplets not in the original grid format which I thought is possible.  
Sincerely,  
Sudheer
