Closed
Description
I'm trying to plot imshow (it inverts Y-axis) and quiver on the same axes and I see the incorrect direction of vectors for Y-axis. In MATLAB the analogous code working correctly.
My code for example:
import numpy as np
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt
h = 100
w = 100
# test image (white square)
image = np.zeros((h, w))
image[20:79, 20:79] = 1
# compute X, Y gradients
gx = ndimage.convolve1d(image, [1, 0, -1], axis=1)
gy = ndimage.convolve1d(image, [1, 0, -1], axis=0)
# compute magnitude
mg = np.hypot(gx, gy)
# grid for quiver
x, y = np.meshgrid(np.arange(0, w), np.arange(0, h))
fig, ax = plt.subplots(2, 1)
ax1, ax2 = ax
ax1.set_title('Gradient mag image and Quiver')
ax1.imshow(mg, cmap=plt.cm.gray)
ax1.quiver(x, y, gx, gy, color='g')
ax2.set_title('Gradient Quiver')
ax2.set_xlim([0, w])
ax2.set_ylim([0, h])
ax2.set_aspect('equal')
ax2.quiver(x, y, gx, gy, color='g')
plt.show()