Superimpose a quiver plot on top of a picture

Hi,
I want to superimpose vector field on top of a TIFF figure!! my vector fields are in '.struct' format, but apparently the vectors are always appear below the figure!! Does anyone know why this happen? & how to superimpose a quiver plot onto a figure?! Here is my code: close all clear all
U=load('VelU - 5m1p2s1.mat');
W=load('VelW - 5m1p2s1.mat')
img = imread('fc2_save_2014-11-17-213936-0000.tif');
imagesc(img);
hold on;
X = U(1,1).x(20:1:64,20:1:64);
Y = U(1,1).y(20:1:64,20:1:64);
Velu = U(1,1).u(20:1:64,20:1:64);
Velw = W(1,1).w(20:1:64,20:1:64);
quiver(X,Y,Velu,Velw, 'y','linewidth',2);

 Accepted Answer

Your image is plotted with x and y in units of pixels (from 1 to 1024), but your quiver plot spans the range 0.15 to 0.45. Replace your imagesc line with
imagesc(unique(X),unique(Y),img);

2 Comments

Yes, changing the image range make it works finally! Thank you Chad!
You should verify that those pixels are properly registered. That is, make sure that each pixel in img is assigned to the proper x and y coordinates.

Sign in to comment.

More Answers (1)

Sometimes stacking gets a little confused, especially depending on the renderer and Matlab distribution. You can try
h = quiver(X,Y,Velu,Velw, 'y','linewidth',2);
uistack(h,'top')
or place the arrows at a higher z value with quiver3 like this:
quiver3(X,Y,ones(Velu),Velu,Velw,zeros(Velu) 'y','linewidth',2);

1 Comment

Oops, that should be
quiver3(X,Y,ones(size(Velu)),Velu,Velw,zeros(size(Velu)) 'y','linewidth',2);

Sign in to comment.

Categories

Asked:

on 31 Dec 2014

Commented:

on 31 Dec 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!