#!/usr/bin/env python
from numpy import arange, meshgrid, pi, sin, cos
from matplotlib.pyplot import subplot, imshow, show, quiver

# Create sample axes
x = arange(-100, 101)
y = arange(-100, 101)
xx = arange(-100, 101, 10)
yy = arange(-100, 101, 10)

Y, X = meshgrid(x, y)
YY, XX = meshgrid(yy, xx)

# Configure constants
A = 1
B = 2
V = 6 * pi / 201
W = 4 * pi / 201

# Create sample data
F = A * sin(V * X) + B * cos(W * Y)
Fx = A * V * cos(V * X)
Fy = -B * W * sin(W * Y)
FFx = -A * V ** 2 * sin(V * XX)
FFy = -B * W ** 2 * cos(W * YY)

# Plot F, Fx and Fy sample data next to each other
# Show FFx and FFy as a quiver plot over F
extent = (-100, 100) * 2
subplot(121, title='First derivatives')
imshow(Fy * Fx, cmap='gray', extent=extent)
subplot(122, title='Second derivatives')
imshow(F, cmap='gray', extent=extent)
quiver(yy, xx, FFy, -FFx, color='red')
show()
