Home > bml > annot > bml_annot_plot.m

bml_annot_plot

PURPOSE ^

BML_ANNOT_PLOT plots an annotation table

SYNOPSIS ^

function bml_annot_plot(cfg, annot, varargin)

DESCRIPTION ^

 BML_ANNOT_PLOT plots an annotation table

 Use as
   bml_annot_plot(annot, varargin)
   bml_annot_plot(cfg, annot, varargin)

 cfg - configuration structure
 annot - annotation table
 varargin - further arguments for plot

 cfg.y - char indicating variable to use for y axis. Default to 'id'
 cfg.facet - char indicating variable by wich to facet the plot
 cfg.subplot_m - number of rows of the subplot layout. Defaults to the
         number of levels of the facet variable
 cfg.subplot_n - number of columns of the subplot layout. Defaults to 1
 cfg.subplot_p - start index of the subplot. Defaults to 0.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bml_annot_plot(cfg, annot, varargin)
0002 
0003 % BML_ANNOT_PLOT plots an annotation table
0004 %
0005 % Use as
0006 %   bml_annot_plot(annot, varargin)
0007 %   bml_annot_plot(cfg, annot, varargin)
0008 %
0009 % cfg - configuration structure
0010 % annot - annotation table
0011 % varargin - further arguments for plot
0012 %
0013 % cfg.y - char indicating variable to use for y axis. Default to 'id'
0014 % cfg.facet - char indicating variable by wich to facet the plot
0015 % cfg.subplot_m - number of rows of the subplot layout. Defaults to the
0016 %         number of levels of the facet variable
0017 % cfg.subplot_n - number of columns of the subplot layout. Defaults to 1
0018 % cfg.subplot_p - start index of the subplot. Defaults to 0.
0019 
0020 if istable(cfg)
0021   if ~exist('annot','var')
0022     annot = [];
0023   end
0024   varargin = [annot, varargin];
0025   annot = cfg;
0026   cfg=[];
0027 end
0028 
0029 yvar      = bml_getopt_single(cfg,'y','id');
0030 facetvar  = bml_getopt_single(cfg,'facet');
0031 
0032 annot = bml_annot_table(annot);
0033 
0034 if isempty(varargin)
0035   varargin={'LineWidth',0.5};
0036 end
0037 
0038 if isempty(facetvar)
0039   for i=1:height(annot)
0040     hold on;
0041     annot_yvar = annot.(yvar);
0042     plot([annot.starts(i),annot.ends(i)],[annot_yvar(i),annot_yvar(i)],varargin{:})
0043     ylabel(yvar);
0044     xlabel('Time (s)');
0045   end
0046 else
0047     
0048   assert(ismember(facetvar,annot.Properties.VariableNames),'unknown variable %s',facetvar)
0049   u=unique(annot.(facetvar));
0050   
0051   subplot_m = bml_getopt(cfg,'subplot_m',length(u));
0052   subplot_n = bml_getopt(cfg,'subplot_n',1);
0053   subplot_p = bml_getopt(cfg,'subplot_p',0);
0054   
0055   for i=1:length(u)
0056     db = annot(strcmp(annot.(facetvar),u(i)),:);
0057     subplot(subplot_m,subplot_n,subplot_p+i);
0058     db_yvar = db.(yvar);
0059     for j=1:height(db)
0060       hold on;
0061       plot([db.starts(j),db.ends(j)],[db_yvar(j),db_yvar(j)],varargin{:})
0062     end
0063     ylabel(u(i));
0064     if i == length(u)
0065       xlabel('Time (s)');
0066     end
0067     xlim([min(annot.starts),max(annot.ends)]);
0068   end
0069 end
0070 
0071

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005