source: issm/trunk/src/m/model/plot/plot_quiver3.m@ 9684

Last change on this file since 9684 was 9684, checked in by seroussi, 14 years ago

added initialization class

File size: 2.5 KB
Line 
1function plot_quiver3(x,y,z,u,v,w,options),
2%PLOT_QUIVER3 - 3d quiver plot with colors
3%
4% to be perfected tomorrow
5%
6% Usage:
7% plot_quiver3(x,y,z,u,v,w,options)
8%
9% Example:
10% plot_quiver(md.x,md.y,md.z,md.initialization.vx,md.initialization.vy,md.initialization.vz,options);
11
12%keep only non NaN elements
13pos=find(~isnan(x) & ~isnan(y) & ~isnan(z) & ~isnan(u) & ~isnan(v) & ~isnan(w));
14x=x(pos); y=y(pos); z=z(pos);
15u=u(pos); v=v(pos); w=w(pos);
16
17%get norm Min and Max
18Norm=sqrt(u.^2+v.^2+w.^2);
19Min=min(Norm);
20Max=max(Norm);
21
22%process options: scaling factor?
23scalingfactor=getfieldvalue(options,'scaling',0.40);
24
25%number of colors?
26colorlevels=getfieldvalue(options,'colorlevels',NaN);
27if isnumeric(colorlevels),
28 if isnan(colorlevels),
29 numcolors=30;
30 else
31 numcolors=colorlevels;
32 end
33 levels=round_ice(linspace(Min,Max,numcolors+1),2);
34else
35 levels=zeros(1,length(colorlevels)+2);
36 levels(1)=Min;
37 for i=1:length(colorlevels)
38 levels(i+1)=colorlevels{i};
39 end
40 levels(end)=Max;
41 levels=sort(unique(levels));
42 numcolors=length(levels)-1;
43end
44
45%set the colormap
46if numcolors==2;
47 %blue and red
48 c=[0 0 1;1 0 0];
49elseif numcolors==3,
50 %blue yellow and red
51 c=[0 0 1;1 1 0;1 0 0];
52else
53 %let jet choose
54 c=colormap(jet(numcolors));
55end
56
57%Scale data
58if strcmpi(getfieldvalue(options,'autoscale','on'),'off'),
59 delta=((min(x)-max(x))^2+(min(y)-max(y))^2)/numel(x);
60 u=scalingfactor*sqrt(delta)*u./Norm;
61 v=scalingfactor*sqrt(delta)*v./Norm;
62else
63 delta=((min(x)-max(x))^2+(min(y)-max(y))^2)/numel(x);
64 u=scalingfactor*sqrt(delta)*u./max(Norm);
65 v=scalingfactor*sqrt(delta)*v./max(Norm);
66end
67
68%loop over the number of colors
69hold on
70h=[];
71for i=1:numcolors
72 pos=find( (Norm>=levels(i)) & (Norm<=levels(i+1)) );
73 hprime=quiver3(x(pos),y(pos),z(pos),u(pos),v(pos),w(pos),'Color',c(i,:),'ShowArrowHead','on','AutoScale','off');
74 h=[h;hprime];
75end
76
77%take care of colorbar
78if ~strcmpi(getfieldvalue(options,'colorbar','on'),'off'),
79
80 %build ticks
81 hcb=colorbar('peer',gca,'location','EastOutside');
82 ticklabel=cell(1,length(levels));
83 for i=1:length(levels),
84 ticklabel{i}=num2str(round_ice(levels(i),3));
85 end
86 tickpos=1:numcolors+1;
87
88 %remove ticks if to many have been created
89 proportion=round(length(levels)/10);
90 if proportion>1,
91 ticklabel=ticklabel(1:proportion:end);
92 tickpos=tickpos(1:proportion:end);
93 end
94
95 %draw colorbar
96 set(hcb,'YTickLabel',ticklabel,'YTick',tickpos);
97 %position
98 if exist(options,'colorbarpos'),
99 set(hcb,'Position',getfieldvalue(options,'colorbarpos'));
100 end
101 %fontsize
102 fontsize=getfieldvalue(options,'fontsize',14);
103 set(hcb,'FontSize',fontsize);
104end
Note: See TracBrowser for help on using the repository browser.