Changeset 5421


Ignore:
Timestamp:
08/19/10 11:45:55 (15 years ago)
Author:
Eric.Larour
Message:

plot_histnorm now called plot_qmuhistnorm. Every qmu related plot should start with plot_qmu...
we now try to call the qmu/plot/ subroutines from John, so as to make it more maintainable.

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  
    3333                        plot_segmentnumbering(md,options,subplotwidth,i);
    3434                        return;
    35                 case 'histnorm',
     35                case 'qmuhistnorm',
    3636                        plot_qmuhistnorm(md,options,subplotwidth,i);
    3737                        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
    3847                case 'part_hist',
    3948                        plot_parthist(md,options,nlines,ncols,i);
     
    4554                        plot_gridnumbering(md,options,subplotwidth,i);
    4655                        return;
    47                 case 'qmu_mass_flux_segments',
    48                         plot_qmu_mass_flux_segments(md,options,nlines,ncols,i);
    49                         return;
    50 
     56               
    5157                case 'highlightgrids',
    5258                        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 %
     1function plot_qmuhistnorm(md,options,width,i);
     2
     3%recover histnorm data
     4if ~exist(options,'qmudata')
     5        error('plot_qmuhistnorm error message: option qmudata is required');
     6else
     7        qmudata=getfieldvalue(options,'qmudata');
     8end
     9
     10%process options for the qmu plot:
     11
    2012%    hmin          (numeric, minimum for histogram)
    2113%    hmax          (numeric, maximum for histogram)
    2214%    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)
    5621%
    5722
     23qmuoptions='';
    5824
    59 function plot_qmuhistnorm(md,options,width,i);
     25if exist(options,'hmin'), hmin=getfieldvalue(options,'hmin'); qmuoptions=[qmuoptions ',''hmin'',' num2str(hmin)]; end
     26if exist(options,'hmax'), hmax=getfieldvalue(options,'hmax'); qmuoptions=[qmuoptions ',''hmax'',' num2str(hmax)]; end
     27if exist(options,'hnint'), hnint=getfieldvalue(options,'hnint'); qmuoptions=[qmuoptions ',''hnint'',' num2str(hnint)]; end
     28if exist(options,'ymin1'), ymin1=getfieldvalue(options,'ymin1'); qmuoptions=[qmuoptions ',''ymin1'',' num2str(ymin1)]; end
     29if exist(options,'ymax1'), ymax1=getfieldvalue(options,'ymax1'); qmuoptions=[qmuoptions ',''ymax1'',' num2str(ymax1)]; end
     30if exist(options,'ymin2'), ymin2=getfieldvalue(options,'ymin2'); qmuoptions=[qmuoptions ',''ymin2'',' num2str(ymin2)]; end
     31if exist(options,'ymax2'), ymax2=getfieldvalue(options,'ymax2'); qmuoptions=[qmuoptions ',''ymax2'',' num2str(ymax2)]; end
     32if exist(options,'cdfplt'), cdfplt=getfieldvalue(options,'cdfplt'); qmuoptions=[qmuoptions ',''cdfplt'',' cdfplt]; end
     33if exist(options,'cdfleg'), cdfleg=getfieldvalue(options,'cdfleg'); qmuoptions=[qmuoptions ',''cdfleg'',' cdfleg]; end
    6034
    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
     36eval(['plot_hist_norm(qmudata' qmuoptions ');']);
  • issm/trunk/src/m/classes/public/plot/plotdoc.m

    r4709 r5421  
    4646disp('                  - ''transient_movie_time'': time for each image (default 2 seconds)');
    4747disp('                  - ''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');
     48disp('                  - ''qmuhistnorm'': histogram normal distribution. needs option qmudata');
    5049disp('                  - ''part_hist'': partitioning node and area histogram');
    51 
    52 answer = lower(input(['more?(y/n) \n'],'s'));
    53 if ~strcmp(answer,'y'), return, end
    5450
    5551disp('       ''alloptions'': apply the options to all subplots if ''on''');
     
    125121disp('       ''wrapping'': repeat ''n'' times the colormap (''n'' must be an integer)');
    126122disp('       ''unit'': by default, in m, otherwise, ''km'' is available');
    127 disp('       ''histnorm_data'': data for histnorm plot.');
     123disp('       ''qmudata'': data for qmu  plots.');
    128124disp('                  {dresp1   ,dresp2  ,hmin,hmax,hnint} or {samp,desc,mu,sigma,hmin,hmax,hnint}');
    129125disp('                  where dresp1 is a structure array of responses (where we need samp and desc), ');
     
    131127disp('                  hmin,hmax and hnint are the minimum, maximum and number of intervals of the histogram (optional)');
    132128disp('       ''position'': position of figure. specify name of person for which position settings are hardcoded in applyoptions.m');
     129disp('       ''hmin'': (numeric, minimum for histogram)');
     130disp('       ''hmax'': (numeric, maximum for histogram)');
     131disp('       ''hnint'': (numeric, number of intervals for histogram)');
     132disp('       ''ymin1'': (numeric, minimum of histogram y-axis)');
     133disp('       ''ymax1'': (numeric, maximum of histogram y-axis)');
     134disp('       ''ymin2'': (numeric, minimum of cdf y-axis)');
     135disp('       ''ymax2'': (numeric, maximum of cdf y-axis)');
     136disp('       ''cdfplt'': (char, ''off'' to turn off cdf line plots)');
     137disp('       ''cdfleg'': (char, ''off'' to turn off cdf legends)');
    133138disp('       any options (except ''data'') can be followed by ''#i'' where ''i'' is the subplot number, or ''#all'' if applied to all plots');
    134139disp('  ');
Note: See TracChangeset for help on using the changeset viewer.