Quiver demo

URL: http://matplotlib.org/examples/pylab_examples/quiver_demo.html

Most examples work across multiple plotting backends, this example is also available for:

In [1]:
import numpy as np
import holoviews as hv

Define data

In [2]:
xs, ys = np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2)
X, Y = np.meshgrid(xs, ys)
U = np.cos(X)
V = np.sin(Y)


In [3]:
%%opts VectorField [aspect=1.5 fig_size=200]
mag = np.sqrt(U**2 + V**2)
angle = (np.pi/2.) - np.arctan2(U/mag, V/mag)
hv.VectorField((X.flat, Y.flat, angle.flat, mag.flat)).relabel('Arrows scale with plot width, not view')
In [4]:
%%opts VectorField [aspect=1.5 fig_size=200] Scatter (color='red')
(hv.VectorField((xs[::3], ys[::3], angle[::3, ::3], mag[::3, ::3])) *\
hv.Scatter((X[::3, ::3].flat, Y[::3, ::3].flat))).relabel(group="pivot='mid'; every third arrow; units='inches'")
In [5]:
%%opts VectorField [aspect=1.5 fig_size=200 size_index=3 color_index=3] (pivot='tip') Points (color='black' s=5)
hv.VectorField((xs, ys, angle, mag), label="pivot='tip'; scales with x view") * hv.Points((X.flat, Y.flat))

Download this notebook from GitHub (right-click to download).