Home > database > ensemble_plotfun.m

ensemble_plotfun

PURPOSE ^

Returns a function handle to one of the plotting sub-functions.

SYNOPSIS ^

function fh = ensemble_plotfun(plot_name)

DESCRIPTION ^

 Returns a function handle to one of the plotting sub-functions.
 fh = ensemble_plotfun(plot_name);

 Returns a function handle to one of the plotting sub-functions.  Calling the
 function without any arguments returns the list of available functions

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fh = ensemble_plotfun(plot_name)
0002 % Returns a function handle to one of the plotting sub-functions.
0003 % fh = ensemble_plotfun(plot_name);
0004 %
0005 % Returns a function handle to one of the plotting sub-functions.  Calling the
0006 % function without any arguments returns the list of available functions
0007 %
0008 
0009 % 02/18/07 Petr Janata
0010 
0011 plotfun_names = {'plot_hist','plot_distrib_by_cat'};
0012 fh = [];
0013 if nargin < 1
0014   fprintf('Available plotting functions:\n');
0015   fprintf('\t%s\n', cell2str(plotfun_names,'\n'));
0016   return
0017 end
0018 
0019 if isempty(strmatch(plot_name,plotfun_names))
0020   fprintf('Unable to find desired function: %s\n', plot_name);
0021 else
0022   fh = str2func(plot_name);
0023 end
0024 
0025 end % function fh = ensemble_plotfun(plot_name)
0026 
0027 %
0028 % Main plotting functions
0029 %
0030 function out_pp = plot_hist(data_st,params)
0031   pp = params.figs;
0032 
0033   % Parse some of the input parameters
0034   try use_fig = params.use_fig;
0035   catch 
0036     try use_fig = pp.start_fignum; catch use_fig = []; end
0037   end
0038   
0039   try use_axes = params.use_axes; catch use_axes = []; end
0040   
0041   try labelfontsize = params.axislabelfontsize; catch labelfontsize = 9; end
0042   
0043   col = set_var_col_const(data_st.vars);
0044   
0045   ncat = length(params.qinfo.enum_values);
0046   nitems = data_st.data{col.nitems};
0047 
0048   max_chars_per_line = 50;
0049   
0050   %
0051   % Generate a figure that summarizes the distributions across categories
0052   %
0053   if isempty(use_fig)
0054     figure
0055   else
0056     figure(use_fig)
0057   end
0058   
0059   nax = 0;
0060   
0061   nax=nax+1;
0062   if ~isempty(use_axes)
0063     axes(use_axes)
0064   end
0065   
0066   % Plot the data
0067   bs = bar(1:ncat,data_st.data{col.mean});
0068   add_errorbars(bs,data_st.data{col.std}'/sqrt(data_st.data{col.nitems}));
0069   set(gca,'xtick',[],'xlim',[0 ncat+1])
0070   set(gca,'activepositionproperty','outerposition')
0071 
0072   ax(nax) = gca;
0073   
0074   % Set axes formatting
0075   
0076   % Add xtick labels as text objects so that we can rotate them
0077   for icat = 1:ncat
0078     label_text = cell2str(linewrap(params.qinfo.enum_values{icat},18),'\n');
0079     text(icat,0,label_text,'rotation',-90, ...
0080     'horizontalalign','left', ...
0081     'verticalalign','middle', ...
0082     'fontsize', labelfontsize);
0083   end
0084   
0085   try ylim = pp.ylim; catch ylim=[]; end
0086   if isempty(ylim)
0087     ylim = [0 1.2*max(data_st.data{col.mean})];
0088   end
0089   set(gca,'ylim',ylim)
0090   
0091   try ylabel_str = pp.ylabel; catch ylabel_str = ''; end
0092   ylabel(ylabel_str)
0093   
0094   if ~isfield(pp,'title')
0095     pp.title = '';
0096   end
0097   title(pp.title)
0098   
0099   if ~isfield(pp,'add_nitems') || pp.add_nitems
0100     th = add_nitems_txt(data_st.data{col.nitems});
0101   end  
0102 
0103   % Add a page header
0104   try add_pagehdr = params.add_pagehdr; catch add_pagehdr = 1; end
0105   if add_pagehdr
0106     pp.pagehdr.title = sprintf(['%s\nQuestion (%1.2f): %s'], pp.title, params.qinfo.compqid, ...
0107     cell2str(linewrap(params.qinfo.question_text,max_chars_per_line),'\n'));
0108     nax = nax+1;
0109     ax(nax)=add_fighdr(pp.pagehdr);
0110     pp.fig.title = pp.pagehdr.title;
0111   end
0112   
0113   if isfield(pp,'write2file') && pp.write2file
0114     fprintf('Printing figure to file: %s\n', pp.figfname);
0115     print(pp.figfname, pp.printargs{:})
0116   end
0117   
0118   pp.fignum = gcf;
0119   pp.axes = ax;
0120   
0121   out_pp = pp;
0122 end % plot_hist()
0123 
0124 
0125 function pp = plot_distrib_by_cat(data_st,params)
0126   pp = params.figs;
0127   max_chars_per_line = 50;
0128 
0129   if ~isstruct(data_st)
0130     tmp.vars = {'prop'};
0131     tmp.data = {data_st};
0132     data_st = tmp;
0133   end
0134   col = set_var_col_const(data_st.vars);
0135   ncat = length(params.qinfo.enum_values);
0136   nitems = size(data_st.data{col.prop},1);
0137 
0138   %
0139   % Generate a figure that shows distributions of responses across items
0140   % separately for each enum category
0141   %
0142   if isfield(pp,'start_fignum')
0143     figure(pp.start_fignum+nfig)
0144   else
0145     figure
0146   end
0147   
0148   nax = 0;
0149   ax = [];
0150   
0151   try ncol = pp.ncol; catch ncol = 3; end
0152   try tick_interval = pp.tick_interval; catch tick_interval = 0.1; end
0153   hist_scale = 0:tick_interval:1;
0154   
0155   for icat = 1:ncat
0156     nax = nax+1;
0157     ax(nax) = subplot(fix(ncat/ncol)+rem(ncat,ncol),ncol,icat);
0158     hist_vals = hist(data_st.data{col.prop}(:,icat),hist_scale);
0159     bar(hist_scale,hist_vals)
0160     set(gca,'xtick',0:tick_interval:1,'xlim',[-0.05 1.05])
0161     set(gca,'ylim',[0 1.1*max(hist_vals)])
0162     title_str = params.qinfo.enum_values{icat};
0163     if strcmpi(title_str,'parent')
0164       title_str = [title_str ' '];
0165     end
0166     title(title_str)
0167     if ~isfield(pp,'add_nitems') || pp.add_nitems
0168       th = add_nitems_txt(nitems);
0169     end  
0170   end % for icat=
0171   
0172   pp.fig.fignum = gcf;
0173 
0174   if ~isfield(pp,'title')
0175     pp.title = '';
0176   end
0177 
0178   pp.pagehdr.title = sprintf(['%s\nQuestion (%1.2f): %s'], pp.title, params.qinfo.compqid,...
0179       cell2str(linewrap(params.qinfo.question_text,max_chars_per_line),'\n'));
0180   nax = nax+1;
0181   ax(nax)=add_fighdr(pp.pagehdr);
0182 
0183   pp.fig.title = pp.pagehdr.title;
0184   pp.fig.axes = ax;
0185 
0186   if isfield(pp,'write2file') && pp.write2file
0187     fprintf('Printing figure to file: %s\n', pp.figfname);
0188     print(pp.figfname, pp.printargs{:})
0189   end
0190 
0191   out_pp = pp;
0192 end % function pp = plot_distrib_by_cat(data_st,params)
0193 
0194 
0195 %
0196 % Internal support functions
0197 %
0198 
0199 function th = add_nitems_txt(nitems,params)
0200   th = text(0.95,0.95,sprintf('N=%d', nitems), ...
0201       'units','norm', ...
0202       'horizontalalign','right', ...
0203       'verticalalign', 'top');
0204 end % function add_nitems_txt(nitems,params)

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003