Ignore:
Timestamp:
08/18/09 09:50:07 (16 years ago)
Author:
Mathieu Morlighem
Message:

Added quiver plot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/classes/public/plot/plot_quiver.m

    r1740 r1744  
    1 function plot_quivervel(md,options_structure,width,i);
    2 %PLOT_QUIVERVEL - plot arrow field of 2d velocities
     1function plot_quiver(x,y,u,v,options_structure),
     2%PLOT_QUIVER - quiver plot with colors
     3%
     4%   to be perfected tomorrow
    35%
    46%   Usage:
    5 %      plot_quivervel(md,options_structure,width,i);
     7%      plot_quiver(x,y,u,v,options_structure)
    68%
    7 %   See also: PLOTMODEL
     9%   Example:
     10%      plot_quiver(md.x,md.y,md.vx,md.vy,options_structure);
    811
    9 %process data and model
    10 [x y z elements is2d]=processmesh(md,options_structure);
    11 [vx isongrid isquiver]=processdata(md,md.vx,options_structure);
    12 [vy isongrid isquiver]=processdata(md,md.vy,options_structure);
     12%get norm Min and Max
     13Norm=sqrt(u.^2+v.^2);
     14Min=min(Norm);
     15Max=max(Norm);
    1316
    14 %plot mesh quivervel
    15 subplot(width,width,i);
    16                                        
    17 %quiver 2d
    18 if ~isnan(options_structure.density)
    19         x=x(1:options_structure.density:end);
    20         y=y(1:options_structure.density:end);
    21         vx=vx(1:options_structure.density:end);
    22         vy=vy(1:options_structure.density:end);
     17%process options: scaling factor?
     18if isnan(options_structure.scaling),
     19        arrow=0.40;
     20else
     21        arrow=options_structure.scaling;
    2322end
    24 quiver(x,y,vx,vy);
    2523
    26 %apply options
    27 if isnan(options_structure.title)
    28         options_structure.title='Velocity vectors';
    29 end
    30 if isnan(options_structure.colorbar)
    31         options_structure.colorbar=0;
     24%number of colors?
     25if isnumeric(options_structure.colorlevels),
     26        if isnan(options_structure.colorlevels),
     27                numcolors=30;
     28        else
     29                numcolors=options_structure.colorlevels;
     30        end
     31        levels=round_ice(linspace(Min,Max,numcolors+1),2);
     32else
     33        levels=zeros(1,length(options_structure.colorlevels)+2);
     34        levels(1)=Min;
     35        for i=1:length(options_structure.colorlevels)
     36                levels(i+1)=options_structure.colorlevels{i};
     37        end
     38        levels(end)=Max;
     39        levels=sort(unique(levels));
     40        numcolors=length(levels)-1;
    3241end
    33 applyoptions(md,[],options_structure);
     42
     43%set the colormap
     44if numcolors==2;
     45        %blue and red
     46        c=[0 0 1;1 0 0];
     47elseif numcolors==3,
     48        %blue yellow and red
     49        c=[0 0 1;1 1 0;1 0 0];
     50else
     51        %let jet choose
     52        c=colormap(jet(numcolors));
     53end
     54
     55%Scale data
     56delta=((min(x)-max(x))^2+(min(y)-max(y))^2)/numel(x);
     57u=arrow*sqrt(delta)*u./Norm;
     58v=arrow*sqrt(delta)*v./Norm;
     59
     60%loop over the number of colors
     61hold on
     62h=[];
     63for i=1:numcolors
     64        pos=find( (Norm>=levels(i)) & (Norm<=levels(i+1)) );
     65        hprime=quiver(x(pos),y(pos),u(pos),v(pos),'Color',c(i,:),'ShowArrowHead','on','AutoScale','off');
     66        h=[h;hprime];
     67end
     68
     69%take care of colorbar
     70if  0 & ~strcmpi(options_structure.colorbar,'off'),
     71        for i=1:length(levels),
     72                scalevalues(i)=levels(i);
     73                scalestring=[scalestring; sprintf('%8.4g',levels(i))];
     74        end
     75        set(colorbar,'YTickLabel',scalestring,'YTick',scalevalues);
     76        error('debug')
     77end
Note: See TracChangeset for help on using the changeset viewer.