File Exchange

image thumbnail

quiverwcolorbar

version 1.8.0.0 (14.5 KB) by Melissa Day
Generates a quiver plot colored according to vector magnitude and/or user specified axis boundaries.

25 Downloads

Updated 06 Mar 2015

View License

quiverwcolorbar adds functionality to the original quiver function by assigning color to the arrows according to the vector magnitude. The corresponding colorbar spans the minimum and maximum values of the dataset or can be specified by the user. Any changes to the colorbar boundaries change the vector colors accordingly.
Syntax:
quiverwcolorbar(x,y,u,v,scale,'bounds',[colormin colormax])

Inputs:
x, y: Vector locations
u, v: Vector directions (East-West, North-South)
scale: Scalar value to set vector lengths
'bounds': Optional setting to specify colorbar axis minimum and maximum values

Example:
x = rand(1,50).*100;
y = rand(1,50).*100;
u = rand(1,50) .* 10;
v = rand(1,50) .* 10;
scale = 0;
figure; quiverwcolorbar(x',y',u',v',scale); %compare to:
figure; quiverwcolorbar(x',y',u',v',scale,'bounds',[0 10]);

Comments and Ratings (16)

Be very careful using this. The domain is flipped compared to quiver, and it reverses the direction of the v component, so if you flip it manually, remember to pass a negative v-component.

>> scale=2; quiverwcolorbar(X,Y,a4_U_01jul_a,a4_V_01jul_a,scale,'bounds',[0 1]);

Warning: The colorbar TickLength is a scalar quantity. Only the first value will be used.
> In colorbar (line 231)
In quiverwcolorbar (line 190)

its plots but no arrows appear, what should i do?

Thank you for your useful script. I use it a lot in my work. But recently I realized that quiverwcolorbar rotate my domain somehow. Actually, because I use it to plot vectors at a duct cross section and I do average over the whole domain I did not notice this effect. I mean if I plot vector field with the same data by quiver and quiverwcolorbar I have two different results. could you please tell me what to do about that?

Melissa Day

Lio - I don't currently have Matlab access but I expect if you edit the line that says "cmap = jet(64); %toggle type of colormap" to something like cool(64) this might fix your issue.

Hello dear Melissa!

I wanted to ask if you could change the code to make the function able to use a user-defined colormap.
Right now there is a "bug", as only the colorbar itself takes over the colormap setting, while the vectors weirdly stay monochromic.

Ex:
figure
colormap cool
quiverwcolorbar(something)
title(bla)

will give you a figure with a cool colorbar ranging from blue to violet, but the vectors will all be blue (despite different sizes).

I believe that this problem isn't linked to my particular case, as the function works very well if I don't specify a colormap.

Thanks so much!
Lio

weidos

I finished my work with this code ,appreciate to your share .

Melissa Day

Ah, the scale factor doesn't work because I added variables. If you put in at line ~99 (also I will update the file):

if(nin == 3) % quiver(u,v,s)
if(isscalar(varargin{nin}))
scale = varargin{nin};
end
elseif(nin >= 5) % quiver(x,y,u,v,s) or quiver(x,y,u,v,s,'bounds',[start end])
if(isscalar(varargin{5}))
scale = varargin{5};
end
end

you will be able to use a fractional scale like 0.5 or something and make your arrows smaller. You can also play around with alpha, beta, autoscale, and plotarrows to change the appearance of the arrows.

Oh yejin

Thank you for good function.
But I want to change the quiver size. It`s too large for me to ploting. What should I do?

Simon

In Matlab 2014a this gives me an error:

Error using set
Bad property value found.
Object Name: axes
Property Name: 'CLim'
Values must be increasing and non-NaN.

Error in caxis (line 79)
set(ax,'CLim',arg);

Error in quiverwcolorbar (line 185)
caxis([colormin colormax])

It seems to be fixed by adding transposes to line 114, so that line 114 should read:

xyuvvrNN = [x(nonNaNind)',y(nonNaNind)',u(nonNaNind)',v(nonNaNind)',vr(nonNaNind)'];

sundar

Thanks for the quick reply.
I just figured out that when I use imagesc instead of imshow it works fine.

clf;imagesc(Image)
hold on
quiverwcolorbar(x,y,u,v)

This works good.

Melissa Day

sundar, I'm not familiar with imshow, but the velocity coloring and the colorbar are not linked in this program quite like they are normally, which might be an issue. When I use imshow(quiverwcolormap(x',y',u',v',scale,'bounds',[0 10]),jet) with the data from the example I posted, it looks all right though, but that might not be your problem. Normally when I call this program to plot over another image I just use "hold on". Sorry I can't be of more help - I hope you figure it out!

sundar

When I use quiverwcolorbar, I get a very nice colored velocity field from blue to red, using the jet colormap. My velocity range is between 0 and 13 um/min.
When I use imshow to display my image and then call this function, the colorbar is totally weird and it is only blue in color (ranging from 0 to 13 um/min) even though the velocities are colored blue to red.

I do not know what I should change?

Any help will be awesome.

Melissa Day

FYI to everyone, I had a similar problem with http://www.mathworks.com/matlabcentral/fileexchange/7180-quiverc2wcmap and had to add "view([0,-90]);" after I called the plot for it to look right (after doing a clear all), so if anyone is having trouble with this maybe playing with the view will help.

For some reason this is flipping my y-axis and image from increasing to decreasing...

Updates

1.8.0.0

Fixed so scale can be used to change arrow size

1.7.0.0

Minor typo fixes

1.5.0.0

Fixed some typos, added bit in case min(xyuvvrNNs) < colormin

1.3.0.0

changed spacing in description

1.2.0.0

Fixed some typos, added bit in case min(xyuvvrNNs) < colormin

1.1.0.0

n/a

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Quiverc, quiverc2wcmap, vfield_color, quiver2.m v1.2 (Nov 2009)

Inspired: quivermc