Changeset 1744


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

Added quiver plot

Location:
issm/trunk/src/m/classes/public/plot
Files:
2 deleted
7 edited

Legend:

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

    r1606 r1744  
    2323else
    2424        options_struct.density=NaN;
     25end
     26
     27%scaling
     28scalingvalues=findarg(optionstring,'scaling');
     29if ~isempty(scalingvalues),
     30        options_struct.scaling=scalingvalues(1).value;
     31else
     32        options_struct.scaling=NaN;
     33end
     34
     35%colorlevels
     36colorlevels_values=findarg(optionstring,'colorlevels');
     37if ~isempty(colorlevels_values),
     38        options_struct.colorlevels=colorlevels_values.value;
     39else
     40        options_struct.colorlevels=NaN;
    2541end
    2642
  • issm/trunk/src/m/classes/public/plot/plot_manager.m

    r1740 r1744  
    5959                case 'penalties',
    6060                        plot_penalties(md,options_structure,width,i);
    61                         return;
    62                 case 'quiver',
    63                         plot_quiver(md,options_structure,width,i);
    64                         return;
    65                 case 'quiver3',
    66                         plot_quiver3(md,options_structure,width,i);
    67                         return;
    68                 case 'quivervel',
    69                         plot_quivervel(md,options_structure,width,i);
    7061                        return;
    7162                case 'riftvel',
  • 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
  • issm/trunk/src/m/classes/public/plot/plot_quiver3.m

    r1740 r1744  
    1 function plot_quivervel3(md,options_structure,width,i);
    2 %PLOT_QUIVERVEL3 - plot arrow field of 3d velocities
     1function plot_quiver3(x,y,z,u,v,w,options_structure),
     2%PLOT_QUIVER3 - 3d quiver plot with colors
     3%
     4%   to be perfected tomorrow
    35%
    46%   Usage:
    5 %      plot_quivervel3(md,options_structure,width,i);
     7%      plot_quiver3(x,y,z,u,v,w,options_structure)
    68%
    7 %   See also: PLOTMODEL
     9%   Example:
     10%      plot_quiver(md.x,md.y,md.z,md.vx,md.vy,md.vz,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);
    13 [vz isongrid isquiver]=processdata(md,md.vz,options_structure);
     12%get norm Min and Max
     13Norm=sqrt(u.^2+v.^2+w.^2);
     14Min=min(Norm);
     15Max=max(Norm);
    1416
    15 %plot mesh quivervel3
    16 subplot(width,width,i);
     17%process options: scaling factor?
     18if isnan(options_structure.scaling),
     19        arrow=0.40;
     20else
     21        arrow=options_structure.scaling;
     22end
    1723
    18 %quiver 3d
    19 if ~isnan(options_structure.density)
    20         x=x(1:options_structure.density:end);
    21         y=y(1:options_structure.density:end);
    22         z=z(1:options_structure.density:end);
    23         vx=vx(1:options_structure.density:end);
    24         vy=vy(1:options_structure.density:end);
    25         vz=vz(1:options_structure.density:end);
     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;
    2641end
    27 quiver3(x,y,z,vx,vy,vz);
    2842
    29 %apply options
    30 if isnan(options_structure.title)
    31         options_structure.title='Velocity vectors (3D)';
    32 end
    33 if isnan(options_structure.colorbar)
    34         options_structure.colorbar=1;
     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));
    3553end
    36 applyoptions(md,[],options_structure);
     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;
     59w=arrow*sqrt(delta)*w./Norm;
     60
     61%loop over the number of colors
     62hold on
     63h=[];
     64for i=1:numcolors
     65        pos=find( (Norm>=levels(i)) & (Norm<=levels(i+1)) );
     66        hprime=quiver3(x(pos),y(pos),z(pos),u(pos),v(pos),w(pos),'Color',c(i,:),'ShowArrowHead','on','AutoScale','off');
     67        h=[h;hprime];
     68end
     69
     70%take care of colorbar
     71if  0 & ~strcmpi(options_structure.colorbar,'off'),
     72        for i=1:length(levels),
     73                scalevalues(i)=levels(i);
     74                scalestring=[scalestring; sprintf('%8.4g',levels(i))];
     75        end
     76        set(colorbar,'YTickLabel',scalestring,'YTick',scalevalues);
     77        error('debug')
     78end
  • issm/trunk/src/m/classes/public/plot/plot_unit.m

    r1740 r1744  
    5353        if isongrid,
    5454                if is2d,
    55                         quivercolor(x,y,data(:,1),data(:,2));
     55                        plot_quiver(x,y,data(:,1),data(:,2),options_structure);
    5656                else
    57                         quivercolor3(x,y,z,data(:,1),data(:,2),data(:,3));
     57                        plot_quiver3(x,y,z,data(:,1),data(:,2),data(:,3),options_structure);
    5858                end
    5959        else
  • issm/trunk/src/m/classes/public/plot/plotdoc.m

    r1606 r1744  
    1212disp('                Available values for ''data'' are: ');
    1313disp('                  - any field of the model structure. ex: plot(md,''data'',''vel''), or plot(md,''data'',md.vel)');
     14disp('                  - ''basal_drag'': plot the basal drag on the bed (in kPa)');
     15disp('                  - ''basal_dragx'' or ''basal_dragy'' : plot a component of the basal drag on the bed (in kPa)');
    1416disp('                  - ''boundaries'': this will draw all the segment boundaries to the model, including rifts.');
    1517disp('                  - ''deviatoricstress_tensor'': plot the components of the deviatoric stress tensor (tauxx,tauyy,tauzz,tauxy,tauxz,tauyz) if computed');
    1618disp('                  - ''deviatoricstress_principal'': plot the deviatoricstress tensor principal axis and principal values');
    1719disp('                  - ''deviatoricstress_principalaxis1'': arrow plot the first principal axis of the deviatoricstress tensor(replace 1 by 2 or 3 if needed)');
     20disp('                  - ''driving_stress'': plot the driving stress (in kPa)');
    1821disp('                  - ''elements_type'': model used for each element');
    1922disp('                  - ''elementnumbering'': numbering of elements');
     
    2326disp('                  - ''highlightgrids'': to highlight grids (use highlight option to enter the grid list');
    2427disp('                  - ''mesh'': draw mesh using trisurf');
    25 disp('                  - ''quiver'': arrow plot of the velocity in 2d');
    26 disp('                  - ''quiver3'': arrow plot of the velocity in 3d');
    27 disp('                  - ''quivervel'': arrow plot of the velocity superimposed with its magnitude');
    2828disp('                  - ''riftvel'': velocities along rifts');
    2929disp('                  - ''riftrelvel'': relative velocities along rifts');
    3030disp('                  - ''riftpenetration'': penetration levels for a fault');
    31 disp('                  - ''basal_drag'': plot the basal drag on the bed (in kPa)');
    32 disp('                  - ''basal_dragx'' or ''basal_dragy'' : plot a component of the basal drag on the bed (in kPa)');
    33 disp('                  - ''driving_stress'': plot the driving stress (in kPa)');
    3431disp('                  - ''strainrate_tensor'': plot the components of the strainrate tensor (exx,eyy,ezz,exy,exz,eyz) if computed');
    3532disp('                  - ''strainrate_principal'': plot the strainrate tensor principal axis and principal values)');
     
    5451disp('       ''antzoom'': zoom on a given Antarctic basin (''pineislandglacier'',''ronneiceshelf'', type antzoom for a complete list)');
    5552disp('       ''caxis'': modify  colorbar range. (array of type [a b] where b>=a)');
     53disp('       ''colorlevels'':  N or {value1,valu2,value3,...} used if quiver, use different colors for the given number of colors or limits');
    5654disp('       ''colorbar'': add colorbar (string ''on'' or ''off'')');
    5755disp('       ''colorbarpos'': [x,y,dx,dy] where x,y,dx and dy are within [0 1]');
     
    6361disp('       ''density'': density of quivers (one arrow every N nodes, N integer)');
    6462disp('       ''streamlines'': N (number of stream lines) or {[x1 y1],...} (coordinates of seed points) add streanlines on current figure');
    65 disp('       ''wrapping'': repeat ''n'' times the colormap (''n'' must be an integer)');
    6663disp('       ''edgecolor'': same as standard matlab option EdgeColor (color name: ''black'' or RGB array: [0.5 0.2 0.8])');
    6764disp('       ''fontsize'': same as standard matlab option (normal: ''n'',bold: ''b'',light: ''l'',demi: ''d'')');
     
    103100disp('       ''northarrow'': add an arrow pointing north, ''on'' for default value or [x0 y0 length [ratio [width]]] where (x0,y0) are the coordinates of the base, and ratio=headlength/length');
    104101disp('       ''scaleruler'': add a scale ruler, ''on'' for default value or [x0 y0 length width numberofticks] where (x0,y0) are the coordinates of the lower left corner');
     102disp('       ''wrapping'': repeat ''n'' times the colormap (''n'' must be an integer)');
    105103disp(' ');
    106104disp('       any options (except ''data'') can be followed by ''#i'' where ''i'' is the subplot number, or ''#all'' if applied to all plots');
  • issm/trunk/src/m/classes/public/plot/processdata.m

    r1740 r1744  
    115115        data=project2d(md,data,options_structure.layer); %project onto 2d mesh
    116116end
     117
     118%control arrow density if quiverplot
     119if isquiver & ~isnan(options_structure.density)
     120        databak=data;
     121        data=NaN*ones(datasize);
     122        data(1:options_structure.density:end,:)=databak(1:options_structure.density:end,:);
     123        clear databak
     124end
Note: See TracChangeset for help on using the changeset viewer.