Home > functions > internal > dsPlotStudy.m

dsPlotStudy

PURPOSE ^

PLOTSTUDY - Applies a user-specified plotting function to each element of data structure.

SYNOPSIS ^

function [handles, hsp, h2] = dsPlotStudy(data,myplot_handle,varargin)

DESCRIPTION ^

PLOTSTUDY - Applies a user-specified plotting function to each element of data structure.

 **IMPORTANT**: This function should just produce a plot. It should not open
 any new figures or subplots. It can return an axis handle, but this is not
 necessary.

 Arrays the output plots in a grid, similar to dsPlot. Intended for use with
 results from simulation studies varying some aspect of the model or inputs.

 Usage:
   [handles, h2, hsp] = dsPlotStudy(data,myplot_handle)

 Inputs:
     - data: DynaSim data structure (see dsCheckData)
     - myplot_handle: Handle for plotting function.
     - options:
       'textfontsize': default text font size of 10
       'use_subplot_grid': turns on or off subplot grid. Default is on. Off might be faster.

 Outputs:
     - handles: handle of the figure
     - hsp: handle of subplot_grid object
     - h2: return values of myplot_handle (usually will be Line handles)

 Example:
     myfunc = @(x) plot(x.RS_V)
     figure; myunc(data(1));   % Single plot
     PlotFunc(data,@myfunc)    % Grid of all plots

 Dependencies:
     Uses subplot_grid.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [handles, hsp, h2] = dsPlotStudy(data,myplot_handle,varargin)
0002 %PLOTSTUDY - Applies a user-specified plotting function to each element of data structure.
0003 %
0004 % **IMPORTANT**: This function should just produce a plot. It should not open
0005 % any new figures or subplots. It can return an axis handle, but this is not
0006 % necessary.
0007 %
0008 % Arrays the output plots in a grid, similar to dsPlot. Intended for use with
0009 % results from simulation studies varying some aspect of the model or inputs.
0010 %
0011 % Usage:
0012 %   [handles, h2, hsp] = dsPlotStudy(data,myplot_handle)
0013 %
0014 % Inputs:
0015 %     - data: DynaSim data structure (see dsCheckData)
0016 %     - myplot_handle: Handle for plotting function.
0017 %     - options:
0018 %       'textfontsize': default text font size of 10
0019 %       'use_subplot_grid': turns on or off subplot grid. Default is on. Off might be faster.
0020 %
0021 % Outputs:
0022 %     - handles: handle of the figure
0023 %     - hsp: handle of subplot_grid object
0024 %     - h2: return values of myplot_handle (usually will be Line handles)
0025 %
0026 % Example:
0027 %     myfunc = @(x) plot(x.RS_V)
0028 %     figure; myunc(data(1));   % Single plot
0029 %     PlotFunc(data,@myfunc)    % Grid of all plots
0030 %
0031 % Dependencies:
0032 %     Uses subplot_grid.
0033 
0034 % data=dsCheckData(data);
0035 handles=[];
0036 
0037 options=dsCheckOptions(varargin,{...
0038   'textfontsize',10,[],...
0039   'use_subplot_grid',1,{0,1},...
0040   },false);
0041 
0042 textfontsize = options.textfontsize;
0043 use_subplot_grid = options.use_subplot_grid;
0044 
0045 % New code (imported from dsPlot)
0046 num_sims=length(data); % number of simulations
0047 
0048 % make subplot adjustments for varied parameters
0049 if num_sims>1 && isfield(data,'varied')
0050   
0051   % collect info on parameters varied
0052   varied=data(1).varied;
0053   num_varied=length(varied); % number of model components varied across simulations
0054   num_sims=length(data); % number of data sets (one per simulation)
0055   
0056   % collect info on parameters varied
0057   param_mat=zeros(num_sims,num_varied); % values for each simulation
0058   param_cell=cell(1,num_varied); % unique values for each parameter
0059   
0060   % loop over varied components and collect values
0061   for j=1:num_varied
0062     if isnumeric(data(1).(varied{j}))
0063       param_mat(:,j)=[data.(varied{j})]; % values for each simulation
0064       param_cell{j}=unique([data.(varied{j})]); % unique values for each parameter
0065     else
0066       % todo: handle sims varying non-numeric model components
0067       % (eg, mechanisms) (also in dsPlotFR and dsSelect)
0068     end
0069   end
0070   
0071   param_size=cellfun(@length,param_cell); % number of unique values for each parameter
0072   % varied parameter with most elements goes along the rows (everything else goes along columns)
0073   row_param_index=find(param_size==max(param_size),1,'first');
0074   row_param_name=varied{row_param_index};
0075   row_param_values=param_cell{row_param_index};
0076   num_rows=length(row_param_values);
0077   
0078   %num_cols=num_sims/num_rows;
0079   num_figs=1;
0080   
0081   % collect sims for each value of the row parameter
0082   indices={};
0083   for row=1:num_rows
0084     indices{row}=find(param_mat(:,row_param_index)==row_param_values(row));
0085   end
0086   num_per_row=cellfun(@length,indices);
0087   num_cols=max(num_per_row);
0088   sim_indices=nan(num_cols,num_rows);
0089   
0090   % arrange sim indices for each row in a matrix
0091   for row=1:num_rows
0092     sim_indices(1:num_per_row(row),row)=indices{row};
0093   end
0094   %   sim_indices=[];
0095   %   for row=1:num_rows
0096   %     sim_indices=[sim_indices find(param_mat(:,row_param_index)==row_param_values(row))];
0097   %   end
0098 else
0099   sim_indices=ones(1,num_rows); % index into data array
0100   num_cols=1;
0101 end
0102 
0103 ht=320; % height per subplot row (=per population or FR data set)
0104 handles(1) = figure('units','normalized','position',[0,1-min(.33*num_rows,1),min(.25*num_cols,1) min(.33*num_rows,1)]);
0105 if use_subplot_grid; hsp = subplot_grid(num_rows,num_cols); else
0106   hsp=tight_subplot(num_rows,num_cols,[.01 .03],[.05 .01],[.03 .01]);
0107 end
0108 
0109 axis_counter = 0;
0110 for row=1:num_rows
0111   for col=1:num_cols
0112     sim_index=sim_indices(col,row); % index into data array for this subplot
0113     axis_counter=axis_counter+1; % number subplot axis we're on
0114     if isnan(sim_index)
0115       continue;
0116     end
0117     
0118     if use_subplot_grid; hsp.set_gca(axis_counter); else
0119       set(gcf,'CurrentAxes',hsp(axis_counter));
0120     end
0121     
0122     num_pops = 1;
0123     if isfield(data,'varied')
0124       if num_sims>1
0125         % list the parameter varied along the rows first
0126         str=[row_param_name '=' num2str(row_param_values(row)) ': '];
0127         for k=1:num_varied
0128           fld=data(sim_index).varied{k};
0129           if ~strcmp(fld,row_param_name)
0130             val=data(sim_index).(fld);
0131             str=[str fld '=' num2str(val) ', '];
0132           end
0133         end
0134         
0135         if num_pops>1
0136           legend_strings=cellfun(@(x)[x ' (mean)'],pop_names,'uni',0);
0137         end
0138       else
0139         str='';
0140         
0141         for k=1:length(data.varied)
0142           fld=data(sim_index).varied{k};
0143           str=[str fld '=' num2str(data(sim_index).(fld)) ', '];
0144         end
0145       end
0146       text_string{row,col}=['(' strrep(str(1:end-2),'_','\_') ')'];
0147     end
0148     
0149     k=1;
0150     i=sim_index;
0151     % get population name from field (assumes: pop_*)
0152     
0153     % 1.0 plot firing rate heat map
0154     %hsp.figtitle([ text_string{row,col}]);
0155     try
0156       h2{i} = myplot_handle(data(i));
0157     catch       % If myplot_handle doesn't return an output
0158       myplot_handle(data(i));
0159       h2{i} = [];
0160     end
0161     title(text_string{row,col},'FontSize',textfontsize);
0162     
0163     set(gca,'FontSize',textfontsize);
0164   end
0165 end
0166 
0167 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005