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.
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
9 % Every column of data is interpreted as one discrete
function
10 % dof vector forwarded to the params.plot()
function.
13 % varargin: usually called with 3 arguments:
15 % - data - cell of data vectors to be plotted
16 % - grid - the underlying grid
17 % - params - plotting parameters
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.
28 % p : figure handle of plot
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().
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
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.
44 % see also the chosen 'params.plot_function' for its further params-options
46 % Bernard Haasdonk 9.5.2007
49 if nargin < 4 % no callback, open new figure
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],...
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], ...
72 ud.data = varargin{1};
73 ud.grid = varargin{2};
74 ud.params = varargin{3};
77 ud.grid = construct_grid(ud.params);
80 if isfield(ud.params,'title')
81 set(f,'Name',ud.params.title);
84 if ~isfield(ud.params,'clim_tight')
85 if isfield(ud.params, 'clim')
86 ud.params.clim_tight = 0;
88 ud.params.clim_tight = 1;
94 sl = findobj(f,'Tag','slider1');
96 %set(sl,'max',ud.params.nt);
97 %set(sl,'sliderstep',[1/ud.params.nt,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]);
103 set(sl,
'max',size(ud.data{1},2)+eps);
104 set(sl,
'visible',
'off');
107 th = findobj(f,
'Tag',
'text1');
108 set(th,
'String',(
'data slice 1') );
114 if nargin >=4 % callback-function
117 % disp(
'performing callback call of plot_fv_data')
118 th = findobj(gcbf,'Tag','text1');
119 v = round(get(gcbo,'value'));
121 set(th,'String',['data slice ',num2str(v)]);
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 function replot(fh,oh,v)
128 ud = get(fh,'Userdata');
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;
135 ud.params.clim_tight = clt;
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);
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];
154 elseif ~isfield(ud.params,
'clim') || ~iscell(ud.params.clim) || length(ud.params.clim) < i
155 ud.params.clim{i} = [];
158 plot_params = structfun(@(x) extract_plot_param(x, i), ud.params,
'UniformOutput',
false);
160 g = ud.params.plot{i}(ud.grid, d, plot_params);
162 %
if ~isempty(ud.params.clim)
163 % set(
get(g,
'Parent'),
'Clim',ud.params.clim{i});
167 function param = extract_plot_param(x,index)
function p = plot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...
function p = plot_subplot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...