## matplotlib-users

 [Matplotlib-users] "quiver" and other vector plots From: Victoria G. Laidler - 2006-02-01 16:15:29 ```Hi folks, I frequently need to make a vector plot that shows (dx,dy) displacements from a set of (x,y) points. "Quiver" doesn't seem to do quite what I want, although maybe I just can't figure out how to use it. Anyhow here is a function I wrote to do what I want using the pylab interface, in case it can be cleaned up and incorporated into matplotlib for general use. def vectorplot(x,y,dx,dy,scale=1): """ Generate a vector plot with lines emanating from the (x,y) points that represent the (dx,dy) displacement at each point. @param scale: Multiply (dx,dy) by this factor to make the displacements more visible @return: (cell_handle, displacement_handle) which can be used to pass to "legend" """ u=x+scale*dx v=y+scale*dy #loop through to make the plots for i in range(len(x)): dhandle=plot([x[i],u[i]],[y[i],v[i]],'o-b', label='shifts [* %4.1f]'%scale) #then overplot the origin points in a different color chandle=plot(x,y,'sk',label='zone') return (chandle,dhandle) cheers, Vicki Laidler ```
 Re: [Matplotlib-users] "quiver" and other vector plots From: John Hunter - 2006-02-03 02:47:28 ```>>>>> "Victoria" == Victoria G Laidler writes: Victoria> Hi folks, I frequently need to make a vector plot that Victoria> shows (dx,dy) displacements from a set of (x,y) Victoria> points. "Quiver" doesn't seem to do quite what I want, Victoria> although maybe I just can't figure out how to use it. There have been a few gripes about quiver...you are not alone. for i in range(len(x)): dhandle=plot([x[i],u[i]],[y[i],v[i]],'o-b', label='shifts [* %4.1f]'%scale) In general, repeated calls to plot can be very inefficient since a new matplotlib.lines.Line2D object is created each time. In cases like these, you want to use a LineCollection or a PolygonCollection (see matplotlib.collections). There are a number of examples in matplotlib.axes and matplotlib.finance. Search for collections... Thanks! JDH ```