Changeset 5421
- Timestamp:
- 08/19/10 11:45:55 (15 years ago)
- Location:
- issm/trunk/src/m/classes/public/plot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/classes/public/plot/plot_manager.m
r4994 r5421 33 33 plot_segmentnumbering(md,options,subplotwidth,i); 34 34 return; 35 case ' histnorm',35 case 'qmuhistnorm', 36 36 plot_qmuhistnorm(md,options,subplotwidth,i); 37 37 return; 38 39 case 'qmuhistnorm', 40 plot_qmuhistnorm(md,options,subplotwidth,i); 41 return; 42 43 case 'qmu_mass_flux_segments', 44 plot_qmu_mass_flux_segments(md,options,nlines,ncols,i); 45 return; 46 38 47 case 'part_hist', 39 48 plot_parthist(md,options,nlines,ncols,i); … … 45 54 plot_gridnumbering(md,options,subplotwidth,i); 46 55 return; 47 case 'qmu_mass_flux_segments', 48 plot_qmu_mass_flux_segments(md,options,nlines,ncols,i); 49 return; 50 56 51 57 case 'highlightgrids', 52 58 plot_highlightgrids(md,options,subplotwidth,i); -
issm/trunk/src/m/classes/public/plot/plot_qmuhistnorm.m
r2439 r5421 1 % 2 % plot a relative histogram and cdf optionally along with 3 % a normal distribution. 4 % 5 % []=plot_qmuhistnorm(dresp1 ,dresp2 ,hmin,hmax,hnint) 6 % []=plot_qmuhistnorm(samp,desc,mu,sigma,hmin,hmax,hnint) 7 % 8 % where the required input is: 9 % dresp1 (structure array, responses) 10 % or 11 % samp (double array, lists of samples) 12 % desc (cell array, list of descriptions) 13 % 14 % and the optional input is: 15 % dresp2 (structure array, responses) 16 % or 17 % mu (double vector, means) 18 % sigma (double vector, standard deviations) 19 % 1 function plot_qmuhistnorm(md,options,width,i); 2 3 %recover histnorm data 4 if ~exist(options,'qmudata') 5 error('plot_qmuhistnorm error message: option qmudata is required'); 6 else 7 qmudata=getfieldvalue(options,'qmudata'); 8 end 9 10 %process options for the qmu plot: 11 20 12 % hmin (numeric, minimum for histogram) 21 13 % hmax (numeric, maximum for histogram) 22 14 % hnint (numeric, number of intervals for histogram) 23 % 24 % the required fields of dresp1 are: 25 % descriptor (char, description) 26 % sample (double vector, list of samples) 27 % 28 % and the required fields of dresp2 are: 29 % mean (double, mean of sample) 30 % stddev (double, standard deviation of sample) 31 % 32 % for each response in the input array, this function 33 % calculates and plots a relative histogram and CDF of the list 34 % of samples, and annotates it with the description. in 35 % addition, a mean and standard deviation may be supplied or 36 % calculated so that a normal distribution and CDF may be 37 % plotted. 38 % 39 % dresp1 data would typically be contained in the dakota tabular 40 % output file from a sampling analysis, and dresp2 data would 41 % typically be contained in the dakota output file from a local 42 % sensitivity analysis, both read by dakota_out_parse. 43 % 44 % "Copyright 2009, by the California Institute of Technology. 45 % ALL RIGHTS RESERVED. United States Government Sponsorship 46 % acknowledged. Any commercial use must be negotiated with 47 % the Office of Technology Transfer at the California Institute 48 % of Technology. (NTR 47078) 49 % 50 % This software may be subject to U.S. export control laws. 51 % By accepting this software, the user agrees to comply with 52 % all applicable U.S. export laws and regulations. User has the 53 % responsibility to obtain export licenses, or other export 54 % authority as may be required before exporting such information 55 % to foreign countries or providing access to foreign persons." 15 % ymin1 (numeric, minimum of histogram y-axis) 16 % ymax1 (numeric, maximum of histogram y-axis) 17 % ymin2 (numeric, minimum of cdf y-axis) 18 % ymax2 (numeric, maximum of cdf y-axis) 19 % cdfplt (char, 'off' to turn off cdf line plots) 20 % cdfleg (char, 'off' to turn off cdf legends) 56 21 % 57 22 23 qmuoptions=''; 58 24 59 function plot_qmuhistnorm(md,options,width,i); 25 if exist(options,'hmin'), hmin=getfieldvalue(options,'hmin'); qmuoptions=[qmuoptions ',''hmin'',' num2str(hmin)]; end 26 if exist(options,'hmax'), hmax=getfieldvalue(options,'hmax'); qmuoptions=[qmuoptions ',''hmax'',' num2str(hmax)]; end 27 if exist(options,'hnint'), hnint=getfieldvalue(options,'hnint'); qmuoptions=[qmuoptions ',''hnint'',' num2str(hnint)]; end 28 if exist(options,'ymin1'), ymin1=getfieldvalue(options,'ymin1'); qmuoptions=[qmuoptions ',''ymin1'',' num2str(ymin1)]; end 29 if exist(options,'ymax1'), ymax1=getfieldvalue(options,'ymax1'); qmuoptions=[qmuoptions ',''ymax1'',' num2str(ymax1)]; end 30 if exist(options,'ymin2'), ymin2=getfieldvalue(options,'ymin2'); qmuoptions=[qmuoptions ',''ymin2'',' num2str(ymin2)]; end 31 if exist(options,'ymax2'), ymax2=getfieldvalue(options,'ymax2'); qmuoptions=[qmuoptions ',''ymax2'',' num2str(ymax2)]; end 32 if exist(options,'cdfplt'), cdfplt=getfieldvalue(options,'cdfplt'); qmuoptions=[qmuoptions ',''cdfplt'',' cdfplt]; end 33 if exist(options,'cdfleg'), cdfleg=getfieldvalue(options,'cdfleg'); qmuoptions=[qmuoptions ',''cdfleg'',' cdfleg]; end 60 34 61 %recover histnorm data 62 if ~exist(options,'histnorm_data') 63 error('plot_qmuhistnorm error message: option histnorm_data is required'); 64 else 65 varargin=getfieldvalue(options,'histnorm_data'); 66 end 67 68 %recover fontsize 69 fontsize=getfieldvalue(options,'fontsize',18), 70 71 nargin=length(varargin); 72 73 %% process input data and assemble into matrices as needed 74 ivar=1; 75 if isstruct(varargin{ivar}) 76 dresp1=varargin{ivar}; 77 ivar=ivar+1; 78 79 desc=cell (1,length(dresp1)); 80 lsamp=zeros(1,length(dresp1)); 81 for i=1:length(dresp1) 82 lsamp(i)=length(dresp1(i).sample); 83 end 84 samp=zeros(max(lsamp),length(dresp1)); 85 samp(:,:)=NaN; 86 87 for i=1:length(dresp1) 88 desc(i)=cellstr(dresp1(i).descriptor); 89 samp(1:lsamp(i),i)=dresp1(i).sample; 90 end 91 else 92 samp=varargin{ivar}; 93 ivar=ivar+1; 94 95 lsamp(1:size(samp,2))=size(samp,1); 96 97 if ivar <= nargin && iscell(varargin{ivar}) 98 desc=varargin{ivar}; 99 ivar=ivar+1; 100 else 101 desc={}; 102 end 103 end 104 105 if ivar <= nargin && isstruct(varargin{ivar}) 106 dresp2=varargin{ivar}; 107 ivar=ivar+1; 108 109 mu =zeros(1,length(dresp2)); 110 sigma=zeros(1,length(dresp2)); 111 112 for i=1:length(dresp2) 113 mu (i)=dresp2(i).mean; 114 sigma(i)=dresp2(i).stddev; 115 end 116 elseif ivar+1 <= nargin 117 if isnumeric(varargin{ivar}) 118 if ~isempty(varargin{ivar}) 119 mu =varargin{ivar}; 120 else 121 mu =mean(samp); 122 display('Using calculated means.') 123 end 124 end 125 ivar=ivar+1; 126 if isnumeric(varargin{ivar}) 127 if ~isempty(varargin{ivar}) 128 sigma=varargin{ivar}; 129 else 130 sigma=std(samp); 131 display('Using calculated standard deviations.') 132 end 133 end 134 ivar=ivar+1; 135 end 136 137 %% generate the intervals 138 139 if ivar <= nargin && ~isempty(varargin{ivar}) 140 hmin=varargin{ivar}; 141 else 142 hmin=min(min(samp)); 143 end 144 ivar=ivar+1; 145 if ivar <= nargin && ~isempty(varargin{ivar}) 146 hmax=varargin{ivar}; 147 else 148 hmax=max(max(samp)); 149 end 150 ivar=ivar+1; 151 if ivar <= nargin && ~isempty(varargin{ivar}) 152 hnint=varargin{ivar}; 153 else 154 hnint=50; 155 end 156 ivar=ivar+1; 157 edges=hmin:(hmax-hmin)/hnint:hmax; 158 159 %% generate the histogram counts and make them relative 160 161 % note that for the histc function: 162 % n(k) counts the value x(i) if edges(k) <= x(i) < edges(k+1). 163 % The last bin counts any values of x that match edges(end). 164 % Values outside the values in edges are not counted. 165 % Use -inf and inf in edges to include all non-NaN values. 166 167 dhistc=histc(samp,edges); 168 for i=1:size(samp,2) 169 dbelow(i) =length(find(samp(:,i)<edges( 1)))/lsamp(i); 170 dhistc(:,i)=dhistc(:,i) /lsamp(i); 171 dabove(i) =length(find(samp(:,i)>edges(end)))/lsamp(i); 172 end 173 174 if exist('mu','var') && exist('sigma','var') 175 ncol=size(samp,2); 176 for i=1:ncol 177 dbelow(ncol+i)=normcdf(edges( 1),mu(i),sigma(i)); 178 dhistc(1:size(dhistc,1)-1,ncol+i)=... 179 normcdf(edges(2:end ),mu(i),sigma(i))-... 180 normcdf(edges(1:end-1),mu(i),sigma(i)); 181 dabove(ncol+i)=norminv(edges(end),mu(i),sigma(i)); 182 if exist('desc','var') 183 desc(ncol+i)={[desc{i} ' norm']}; 184 end 185 end 186 end 187 188 % draw the bar plot 189 190 hl1=bar(edges(1:end-1),dhistc(1:end-1,:)); 191 ax1=gca; 192 193 % add the annotation 194 ylabel('Relative Frequency','Fontsize',fontsize); 195 196 if exist('desc','var') 197 hleg1=legend(ax1,desc,'Location','NorthWest',... 198 'Interpreter','none'); 199 else 200 hleg1=legend(ax1); 201 end 202 203 %% generate the cumulative distribution functions 204 205 % cdf=zeros(size(dhistc)); 206 % cdf(1,:)=dhistc(1,:); 207 % for i=2:size(dhistc,1) 208 % cdf(i,:)=cdf(i-1,:)+dhistc(i,:); 209 % end 210 cdf=cumsum(dhistc); 211 for i=1:size(dhistc,2) 212 cdf(:,i)=dbelow(i)+cdf(:,i); 213 end 214 if exist('desc','var') 215 ncol=length(desc); 216 for i=1:ncol 217 cdesc(i)={[desc{i} ' cdf']}; 218 end 219 end 220 221 % draw the line plot 222 223 % (see "Using Multiple X- and Y-Axes" and "Overlaying Other 224 % Plots on Bar Graphs", or search on "YAxisLocation right") 225 226 %hold all 227 %hold on 228 %plot(edges,cdf) 229 %plotyy([],[],edges,cdf) 230 231 % ticks from the bar plot will show through, so make ticks 232 % from the line plot match 233 234 nytick=length(get(ax1,'YTick')); 235 ytmax =ceil(max(max(cdf))/0.1-0.1)*0.1; 236 ytinc =ytmax/(nytick-1-1); 237 238 ax2=axes('Position',get(ax1,'Position'),... 239 'XLim',get(ax1,'XLim'),... 240 'YLim',[0 ytinc*(nytick-1)],... 241 'YTick',[0:ytinc:ytinc*(nytick-1)],... 242 'XAxisLocation','bottom','YAxisLocation','right',... 243 'Color','none','Layer','top'); 244 hl2=line(edges(1:end-1),cdf(1:end-1,:),'Parent',ax2); 245 246 % add the annotation 247 248 ylabel('Cumulative Percent','FontSize',fontsize) 249 250 % legend doesn't combine with bar chart above 251 if exist('cdesc','var') 252 hleg2=legend(ax2,cdesc,'Location','NorthEast',... 253 'Interpreter','none'); 254 set(hleg2,'Color','white') 255 else 256 hleg2=legend(ax2); 257 set(hleg2,'Color','white') 258 end 259 260 set(gcf,'PaperPositionMode','auto') 261 %hold off 262 263 264 %apply options. 265 options=addfielddefault(options,'title','Relative Frequency Histogram'); 266 options=addfielddefault(options,'xlabel','Interval Edge Value'); 267 options=addfielddefault(options,'colorbar',0); 268 applyoptions(md,[],options); 35 %use qmu plot 36 eval(['plot_hist_norm(qmudata' qmuoptions ');']); -
issm/trunk/src/m/classes/public/plot/plotdoc.m
r4709 r5421 46 46 disp(' - ''transient_movie_time'': time for each image (default 2 seconds)'); 47 47 disp(' - ''thermaltransient_results'': this will display all the time steps of a thermal transient run'); 48 disp(' - ''normplot'': norm plot'); 49 disp(' - ''histnorm'': histogram normal distribution. needs option histnorm_data'); 48 disp(' - ''qmuhistnorm'': histogram normal distribution. needs option qmudata'); 50 49 disp(' - ''part_hist'': partitioning node and area histogram'); 51 52 answer = lower(input(['more?(y/n) \n'],'s'));53 if ~strcmp(answer,'y'), return, end54 50 55 51 disp(' ''alloptions'': apply the options to all subplots if ''on'''); … … 125 121 disp(' ''wrapping'': repeat ''n'' times the colormap (''n'' must be an integer)'); 126 122 disp(' ''unit'': by default, in m, otherwise, ''km'' is available'); 127 disp(' '' histnorm_data'': data for histnorm plot.');123 disp(' ''qmudata'': data for qmu plots.'); 128 124 disp(' {dresp1 ,dresp2 ,hmin,hmax,hnint} or {samp,desc,mu,sigma,hmin,hmax,hnint}'); 129 125 disp(' where dresp1 is a structure array of responses (where we need samp and desc), '); … … 131 127 disp(' hmin,hmax and hnint are the minimum, maximum and number of intervals of the histogram (optional)'); 132 128 disp(' ''position'': position of figure. specify name of person for which position settings are hardcoded in applyoptions.m'); 129 disp(' ''hmin'': (numeric, minimum for histogram)'); 130 disp(' ''hmax'': (numeric, maximum for histogram)'); 131 disp(' ''hnint'': (numeric, number of intervals for histogram)'); 132 disp(' ''ymin1'': (numeric, minimum of histogram y-axis)'); 133 disp(' ''ymax1'': (numeric, maximum of histogram y-axis)'); 134 disp(' ''ymin2'': (numeric, minimum of cdf y-axis)'); 135 disp(' ''ymax2'': (numeric, maximum of cdf y-axis)'); 136 disp(' ''cdfplt'': (char, ''off'' to turn off cdf line plots)'); 137 disp(' ''cdfleg'': (char, ''off'' to turn off cdf legends)'); 133 138 disp(' any options (except ''data'') can be followed by ''#i'' where ''i'' is the subplot number, or ''#all'' if applied to all plots'); 134 139 disp(' ');
Note:
See TracChangeset
for help on using the changeset viewer.