Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create quiver scale/colorbar

2,178 views
Skip to first unread message

Matthew Watts

unread,
Nov 28, 2002, 5:19:46 AM11/28/02
to
I wonder if anyone can help me I am using the quiver function to plot
wind direction but can not work out how to either color the arrows or
put a scale on the figure. I know that the length of the arrow is
the magnitude.


Thanks


Matthew Watts

Joe Sababa

unread,
Dec 2, 2002, 5:12:14 PM12/2/02
to
Hi,
You can set all line properties using propertyname/propertyvalue
couples the same way as in creating a line object.
Here are the available properties:
Line style
Line width
Color
Marker type
Marker size
Marker face and edge coloring (for filled markers)
In addition you can specify the scale . Example:
quiver(X,Y,U,V,5,'FaceColor','r') % 5 is the scale


Joe
BSTeX- Equation viewer for Matlab
<http://www.geocities.com/bstex2001>

Timothy Hilton

unread,
Dec 2, 2002, 7:56:11 PM12/2/02
to
I am also using the quiver function to plot wind vectors. The scale
argument to the quiver function scales the vectors that are drawn on the
plot. What I haven't yet figured out is a way to create some sort of legend
with a reference vector that is scaled to the magnitudes of the vectors in
the plot. The vectors in the plot are drawn to scale relative to each
other, but from simply looking at the plot it is impossible to tell whether
a particlular vector represents 1 m/s or 5 m/s. It is easy to place an
extra vector of a given magnitude into the plot itself, but it is not a very
elegant solution. It would be nice to be able to place the reference vector
somewhere that is separated from the main plot.

Could anyone suggest a way to do this?

Thanks,
Tim

"Joe Sababa" <joes...@yahoo.com> wrote in message
news:eeb5...@WebX.raydaftYaTP...

Dave

unread,
Dec 3, 2002, 6:23:23 PM12/3/02
to
On Mon, 2 Dec 2002 17:12:14 -0500, "Joe Sababa" <joes...@yahoo.com>
wrote:


I've recently added a function to my Matlab toolbox for plotting wind
(or current) velocity vectors (f_vecPlot, given below). I played
around a bit adding reference vectors at positions specified by the
user (via ginput), etc. but settled on an implementation that properly
scales the data and y-axis, so a scale bar is not necessary. Note that
to use QUIVER to produce vectors that have the proper length and angle
of rotation you shouldn't use autoscaling. This and the other
functions in my toolbox are available for free download at:

http://www.rsmas.miami.edu/personal/djones/

HTH,
Dave


====================================
begin MATLAB code
====================================

function f_vecPlot(jdate,u,v,scale,offset,units);
% - plot time series of velocity vectors
%
% USAGE: f_vecPlot(jdate,u,v,scale,offset,ref,refoff)
%
% jdate = column vector of Julian dates
% u,v = corresponding vector components
% scale = plot scale (default = 1)
% offset = axis offset (default = 0)
% units = velocity units (default = none)
% (e.g., units = 'm/s')
%
% See also: f_julian, f_vecUV, f_vecMagDir, f_windCman,
% f_windstress

% ----- Notes: -----
% This function is used to plot time series of wind or
% current meter velocity vectors using the Matlab's
% QUIVER function. This function is necessary in order
% to obtain vectors that have the proper length and angle
% of rotation. An optional scaling factor can be applied
% allowing the user control over the amount of overlap among
% vectors and/or scaling of vectors relative to the overall
% time series. The Y-axis is scaled accordingly allowing
% easy, visual interpretation of vector length.
%
% U,V components of velocity vectors can be extracted from
% data specifying only Speed and Direction using f_vecUV

% ----- Author(s): -----
% by Dave Jones,<djo...@rsmas.miami.edu> Dec-2002
% http://www.rsmas.miami.edu/personal/djones/
% ----------------- DISCLAIMER: -------------------
% This code is provided as is, with no guarantees
% and is only intended for non-commercial use.
% --------------------------------------------------

% ----- Check input & set defaults: -----
if (nargin < 4), scale = 1; end; % no scaling by default
if (nargin < 5), offset = 0; end; % no offset by default
if (nargin < 6), units = []; end; % no units by default

if (scale==0)
error('You cannot scale vectors by 0');
end

if (size(u,1) ~= size(v,1)) | (size(u,1) ~= size(jdate,1))
error('U,V, and JDATE must be same size!')
end
% ---------------------------------------

nr = size(jdate,1); % # rows

figure;
hold on;

% plot vectors:
h = quiver(jdate,offset+zeros(nr,1),scale*u,scale*v,0,'.b-');

% plot base line:
plot([min(jdate) max(jdate)]',[offset offset]','k-');

% adjust aspect ratio for correct angles and lengths:
daspect(scale*[1 1 1]);

% adjust Y-axis labels:
if (scale ~= 1)
yLabels = get(gca,'yticklabel');
yLabels = num2str(str2num(yLabels)/scale);
set(gca,'yticklabel',yLabels);
end

% adjust plot appearance:
set(gcf,'color','w');
set(gca,'TickDir','out');
xlabel('Julian Date');
ylabel(units);
box off;

hold off

====================================
end MATLAB code
====================================

Susanne

unread,
Dec 4, 2002, 2:53:05 PM12/4/02
to
I had a similar problem when plotting wind velocities at different
height. I needed to get some info fast, and found that the following
method worked well.
I basically drew a contour plot (contour or contourf) and plotted the
quiver on top. That way I could set my contours and also have a
colorbar for comparison.
Just use the magnitude to plot the contours and use the wind
components for the quiver.
It is not a very elegant solution but I got it working within a few
minutes without any fuss. Of course, this method is not particularly
good if you want to see precise values next to each arrow in the
quiver, but it is enough to give you the general idea.
Cheers

Susanne :-)

"Matthew Watts" <m.w...@uea.ac.uk> wrote in message news:<eeb5b...@WebX.raydaftYaTP>...

Dave

unread,
Dec 11, 2002, 8:27:40 PM12/11/02
to
On Tue, 03 Dec 2002 23:23:23 GMT, Dave <Dave[nOsPaM]@phbeads.com>
wrote:

>I've recently added a function to my Matlab toolbox for plotting wind
>(or current) velocity vectors (f_vecPlot, given below).

I'm not sure if this is what the original poster had in mind, but I'll
submit this anyway.

Here's a new version of F_VECPLOT with much improved scaling (the
Y-axis is scaled instead of the X). This is now part of FATHOM, my
Matlab Toolbox for Ecological and Oceanographic Data Analysis.
Available from:

http://www.rsmas.miami.edu/personal/djones/

====================================
begin MATLAB code
====================================

function f_vecPlot(jdate,u,v,scale,units,jRange);


% - plot time series of velocity vectors
%

% USAGE: f_vecPlot(jdate,u,v,scale,units,jRange)


%
% jdate = column vector of Julian dates
% u,v = corresponding vector components

% scale = scale factor (default = 1)
% units = Y-axis label; e.g., units = 'm/s') (default = none)
% jRange = limits of dates to plot (default = auto)
% (e.g., jRange = [min max])
%
% See also: f_julian, f_vecUV, f_shadeBox

% ----- Notes: -----
% This function is used to plot time series of wind or

% current meter velocity vectors using Matlab's QUIVER
% function. This function is necessary in order to obtain
% vectors that have the proper length and angle of rotation.
% An optional scaling factor can be applied allowing the
% user control over the amount of overlap among vectors
% and/or the scaling of vectors relative to the overall
% time series. The X-axis is scaled accordingly. The Y-axis
% allows easy, visual interpretation of vector length.


%
% U,V components of velocity vectors can be extracted from

% data specifying only Speed and Direction using f_vecUV.

% ----- Author(s): -----
% by Dave Jones, Dec-2002


% http://www.rsmas.miami.edu/personal/djones/
% ----------------- DISCLAIMER: -------------------

% This code is provided as is, with no guarantees.
% --------------------------------------------------

% 10-Dec-2002: scaling now operates on the X- vs. Y-axis;
% Y-axis limits can now be specified

% ----- Check input & set defaults: -----
if (nargin < 4), scale = 1; end; % no scaling by default

if (nargin < 5), units = []; end; % no units by default
if (nargin < 6), jRange = []; end; % no range specified

if (scale==0)
error('You cannot scale vectors by 0');
end

if (size(u,1) ~= size(v,1)) | (size(u,1) ~= size(jdate,1))
error('U,V, and JDATE must be same size!')
end
% ---------------------------------------

nr = size(jdate,1); % # rows

figure;
hold on;

% plot vectors:
h = quiver(jdate/scale,zeros(nr,1),u,v,0,'.b-');

% plot base line:
plot([min(jdate/scale) max(jdate/scale)]',[0 0]','k-');

% adjust aspect ratio for correct angles and lengths:

daspect([1 1 1]);

% adjust X-axis limits & labels:
if (scale ~= 1)

if (jRange ~= [])
xlim([jRange(1)/scale jRange(2)/scale]);
end

xLabels = get(gca,'xticklabel'); % get tick labels
xLabels = str2num(xLabels); % convert to numbers
xLabels = num2str(xLabels*scale); % recale values
set(gca,'xticklabel',xLabels); % replace labels
end

% adjust plot appearance:
set(gcf,'color','w');
set(gca,'TickDir','out');

xlabel('Julian Day');

0 new messages