Quiver demo¶
Download this notebook from GitHub (right-click to download).
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
from holoviews import opts
hv.extension('bokeh')
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)
# Convert to magnitude and angle
mag = np.sqrt(U**2 + V**2)
angle = (np.pi/2.) - np.arctan2(U/mag, V/mag)
Plot¶
In [3]:
label = 'Arrows scale with plot width, not view'
opts.defaults(opts.VectorField(height=400, width=500))
vectorfield = hv.VectorField((xs, ys, angle, mag))
vectorfield.relabel(label)
Out[3]:
In [4]:
label = "pivot='mid'; every third arrow"
vf_mid = hv.VectorField((xs[::3], ys[::3], angle[::3, ::3], mag[::3, ::3], ))
points = hv.Points((X[::3, ::3].flat, Y[::3, ::3].flat))
opts.defaults(opts.Points(color='red'))
(vf_mid * points).relabel(label)
Out[4]:
In [5]:
label = "pivot='tip'; scales with x view"
vectorfield = hv.VectorField((xs, ys, angle, mag))
points = hv.Points((X.flat, Y.flat))
(points * vectorfield).opts(
opts.VectorField(magnitude='Magnitude', color='Magnitude',
pivot='tip', line_width=2, title=label))
Out[5]:
Download this notebook from GitHub (right-click to download).