rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_subplot_sequence.m
Go to the documentation of this file.
1 function p = plot_subplot_sequence(varargin)
2 %function p = plot_subplot_sequence(data,grid,params[,callbackfigure, cbhandle])
3 % plotting a sequence of data slices on polygonal 2d grid (constructed from
4 % params if empty) and providing a slider for changing between the data slices.
5 %
6 % A new figure is opened and the handle returned in p. If further parameters
7 % are set, the call is assumed to stem from a callback-function
8 %
9 % Every column of data is interpreted as one discrete function
10 % dof vector forwarded to the params.plot() function.
11 %
12 % parameters:
13 % varargin: usually called with 3 arguments:
14 % @code plot_sequence(data, grid, params) @endcode
15 % - data - cell of data vectors to be plotted
16 % - grid - the underlying grid
17 % - params - plotting parameters
18 % .
19 % Alternatively, there can be 5 arguments:
20 % @code plot_sequence(data, grid, params, callbackfigure, cbhandle) @endcode
21 % This function is set as a callback function for the time slider
22 % uicontrol. The additional arguments are:
23 % - callbackfigure - handle to the figure
24 % - cbhandle - handle to the object calling the callback function. This
25 % is usually the time slider.
26 %
27 % return values:
28 % p : figure handle of plot
29 %
30 % required fields in params:
31 % - 'plot' -- pointer to the plot-function performing the plotting of a
32 % single slice, e.g. plot_element_data(), plot_vertex_data(),
33 % fv_plot(), ldg_plot().
34 %
35 % optional field of params:
36 % - 'title' -- string indicating the title of the newly opened figure
37 % - 'clim' -- 2-vector giving the range of the colormap. If this is set,
38 % identical range is used for all slices. Default is the min and
39 % max of all slices.
40 % - 'clim_tight' -- if this flag is set, the colorbar is set tightly to the
41 % range of every single data slice. Clearly only one of
42 % 'clim' or 'clim_tight' should be set.
43 %
44 % see also the chosen 'params.plot_function' for its further params-options
45 
46 % Bernard Haasdonk 9.5.2007
47 
48 % open figure
49 if nargin < 4 % no callback, open new figure
50 
51  % keyboard;
52  f = figure;
53  di = 0.05;
54  textwidth= 0.15;
55  textheight = 0.03;
56  panel = uipanel(f, 'Title','Control Panel','FontSize', 12, ...
57  'Units', 'normalized', ...
58  'Position', [0.5*di, di, 1-di, 2.0*textheight]);
59  txt = uicontrol('Parent', panel,'Style','text','Units','normalized',...
60  'Position',[0.5*di,di,textwidth,0.9],...
61  'String','Slice 1','Tag','text1');
62  slider = uicontrol('Parent', panel,'Style','slider','Units','normalized',...
63  'Position',[di+textwidth, di ,1-3*di-textwidth, 0.9],...
64  'Tag','slider1',...
65  'Callback','plot_subplot_sequence([],[],[],[],gcbf,gcbo)');
66  ax = uipanel(f, 'Title', 'Plots', 'Units', 'normalized', 'FontSize', 12, ...
67  'Position', [0.5*di, 2*di+textheight, 1-di, 1-3*di+textheight], ...
68  'Tag', 'axesarea');
69 
70  % cb = colorbar;
71  ud = [];
72  ud.data = varargin{1};
73  ud.grid = varargin{2};
74  ud.params = varargin{3};
75 
76  if isempty(ud.grid)
77  ud.grid = construct_grid(ud.params);
78  end;
79 
80  if isfield(ud.params,'title')
81  set(f,'Name',ud.params.title);
82  end;
83 
84  if ~isfield(ud.params,'clim_tight')
85  if isfield(ud.params, 'clim')
86  ud.params.clim_tight = 0;
87  else
88  ud.params.clim_tight = 1;
89  end
90  end
91 
92  set(f,'Userdata',ud);
93 
94  sl = findobj(f,'Tag','slider1');
95  %set(sl,'min',0);
96  %set(sl,'max',ud.params.nt);
97  %set(sl,'sliderstep',[1/ud.params.nt,1]);
98  set(sl,'min',1);
99  if size(ud.data{1},2)>1
100  set(sl,'max',size(ud.data{1},2));
101  set(sl,'sliderstep',[1/(size(ud.data{1},2)-1),1]);
102  else
103  set(sl,'max',size(ud.data{1},2)+eps);
104  set(sl,'visible','off');
105  end;
106  set(sl,'value',1);
107  th = findobj(f,'Tag','text1');
108  set(th,'String',('data slice 1') );
109  replot(f,sl,1);
110 
111  p = f;
112 end
113 
114 if nargin >=4 % callback-function
115  cbf = varargin{4};
116  cbo = varargin{5};
117  % disp('performing callback call of plot_fv_data')
118  th = findobj(gcbf,'Tag','text1');
119  v = round(get(gcbo,'value'));
120  set(gcbo,'value',v)
121  set(th,'String',['data slice ',num2str(v)]);
122  replot(gcbf,gcbo,v);
123  p = gcbf;
124 end
125 
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 function replot(fh,oh,v)
128 ud = get(fh,'Userdata');
129 
130 if ~iscell(ud.params.clim_tight)
131  clt = cell(1, length(ud.data));
132  for i = 1:length(clt)
133  clt{i} = ud.params.clim_tight;
134  end
135  ud.params.clim_tight = clt;
136 end
137 
138 ax = findobj(fh,'Tag','axesarea');
139 for i = 1:length(ud.data);
140  subplot(ud.params.sp_x, ud.params.sp_y, ud.params.index{i}, 'Parent', ax);
141  d = ud.data{i};
142  if isstruct(d)
143  d.t = v;
144  else
145  d = d(:,v);
146  end
147 
148  % if clim_tight, adapt color-range:
149  if ud.params.clim_tight{i} && isnumeric(d)
150  ud.params.clim{i} = [min(min(d)), max(max(d))];
151  if ud.params.clim{i}(1) == ud.params.clim{i}(2)
152  ud.params.clim{i} = ud.params.clim{i} + [-eps, +eps];
153  end
154  elseif ~isfield(ud.params, 'clim') || ~iscell(ud.params.clim) || length(ud.params.clim) < i
155  ud.params.clim{i} = [];
156  end
157 
158  plot_params = structfun(@(x) extract_plot_param(x, i), ud.params, 'UniformOutput', false);
159 
160  g = ud.params.plot{i}(ud.grid, d, plot_params);
161 
162 % if ~isempty(ud.params.clim)
163 % set(get(g, 'Parent'),'Clim',ud.params.clim{i});
164 % end
165 end
166 
167 function param = extract_plot_param(x,index)
168 
169 if iscell(x)
170  param = x{index};
171 else
172  param = x;
173 end
174 
function p = plot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...
Definition: plot_sequence.m:17
function p = plot_subplot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...