File Exchange

image thumbnail


version (3.08 KB) by Bertrand Dano
Creates a color quiver plot with arrows colors according to the magnitude of the vector.


Updated 26 Nov 2008

View Version History

View License

This is a modified version of the function quiver [from C.M. Thompson] to plot velocity vectors as arrows with components (u,v) at the points (x,y) with the color corresponding to the magnitude of the vector and using the current colormap.

Tip: for best results, add set(gcf, 'InvertHardCopy', 'off') after the function to keep the black background on the hardcopy. See attached examples.

Cite As

Bertrand Dano (2021). Quiverc (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (33)

Shelby Henderson

alok pandey

@ Pablo Encinas: To get the classic white background, you can change line 174 and 175 of the function to:
set(gca, 'color', [1 1 1],'Xcolor','k','Ycolor','k');
set(gcf, 'color', [1 1 1]);

@ Bertrand Dano: good work!


Bertrand Dano

@ Robert, not much I can do without the code you used and reach this error.
Try this. If it works, the problem is not quiverc.

clear all; close all; clc
load wind;
u=u(:,:,N); v=v(:,:,N);
colormap jet
colorbar vert

Robert Dresselhaus

Getting this ???
Undefined function or variable 'h1'.

Error in quiverc (line 173)
if nargout>0, hh = [h1;h2;h3]; end

Error in L_Transport2 (line 129)

Mohsen Masoudian

Dhanushka Kularatne


Pablo Encinas

My background is black, how can I change it to classic white?

Rosalinda Lopez

how can I show the corresponding color scale bar on the side of the plot?

Narayani Vedam

I was able to fix it.

yong bao

Great job

nawal eldrogi


Marie Escouflaire

Zhijie Ma


This is just great thanks!


This is awesome. However i tried to look into it to get a '3D' version, like quiver3 as Joe posted june 2013. Does it exist?


Hi Dano, this is a great code! Is there a variation of this code of this using 3D data (similar to quiver3)? Thanks

Tianjin University

I have this error when I run the codes, too.

Tiago Leal

I already found the problem. My code had colormap(gray(2)) before the plot.

Tiago Leal

??? Attempted to access CC(5,1); index out of bounds because size(CC)=[2,3].

Error in ==> quiverc at 134
c1= CC(ii,1); c2= CC(ii,2); c3= CC(ii,3);

I have this error when I run the codes. C(x,1) x is alwyas different and bigger than 2. Anyone can help me??


good job, but one comment: when I use h=quiverc(x,y,U,V,S), it seems the code can not return h? In other words, quiverc(x,y,U,V,S) works, but h=quiverc(x,y,U,V,S) does not work.

Vinesh Rajpaul

Great file, thanks! But -- is there any way to use quiverc.m to create a colour quiver plot, but with all arrows plotted with same lengths? I.e. magnitude of vectors to be indicated solely by color and not length. It's redundant to indicate magnitude both by length and color; moreover, some vectors are often so small (relative to others in the field) that they are "invisible", in which case the colormap is useless anyway. Thanks.

Burak eral

Hi Bertrand;

I am using your cool code quiverc for plotting velocity fields that evolve over time… In your code you normalize colormaps so that red in colorbar refers to max velocity with in frame… I am trying have a global colormap where I insert max value velocity value within my frames so red refers to this value at all times…

I tried to change max(vr(:)) in code below with my global max value but it does not work…

ax = newplot;
next = lower(get(ax,'NextPlot'));
hold_state = ishold;

Do you have an idea how I can go around this ?

Thanks in advance

Alison Rogers

Thanks! This is very useful.

David Kolin

Excellent, except that the color mapping is incorrect if the current colormap is longer than 64. Changing the two int8 calls in quiverc to int16 fixes this problem.

Ching-Fang Lee

It's a very useful tool for ploting! Thanks!

tuna kaskati

Gavita Regunath

Brilliant and extremely useful! Thanks!

Colin Ned

great job, save me much time to write code

Kwijibo Lefever

Not as fast as quiver for large vector/velocity field. But fine otherwise.

Peter Slovinsky

I was working with quiver plots to show current velocity and direction from a moving vessel. The quiverc is perfect for creating a figure that is easy to qualitativy interpret.

Klaas Hartmann

I find the output of quiverc easier to interpret than that of quiver. My only qualm is that it runs a bit slow with the data I am plotting -- I wan't to show a sequence of quiver plots. Also it doesn't seem to handle NaNs in the data automatically (just replace them with 0s)

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

Community Treasure Hunt

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

Start Hunting!