rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_data_sequence.m
1 function plot_data_sequence(varargin)
2 % function plot_data_sequence(model,[grid],data,params[, callbackfigure, cbhandle])
3 %
4 % plotting a sequence of data slices on polygonal
5 % 2d grid (constructed from params if empty) and providing a slider
6 % for changing between the data
7 % slices. A new figure is opened.
8 % If further parameters are set, the call is assumed to
9 % stem from a callback-function
10 %
11 % required fields in params:
12 % plot_function: the name of the plot-function performing
13 % the plotting of a single slice, e.g.
14 % plot_element_data, plot_vertex_data
15 %
16 % optional field of params:
17 % title: string indicating the title of the newly opened figure
18 % clim: 2-vector giving the range of the colormap. If this is
19 % set, identical range is used for all slices. Default is
20 % the min and max of all slices.
21 % clim_tight: if this flag is set, the colorbar is set tightly
22 % to the range of every single data slice. Clearly only clim or
23 % clim_tight should be set.
24 %
25 % see also the chosen params.plot_function for its further params-options
26 
27 % Bernard Haasdonk 9.5.2007
28 
29 % open figure
30 if nargin < 5 % no callback, open new figure
31 
32  f = figure;
33  di = 0.1;
34  textwidth= 0.15;
35  textheight = 0.05;
36  txt = uicontrol(f,'Style','text','Units','normalized',...
37  'Position',[di,di,textwidth,textheight],...
38  'String','Slice 1','Tag','text1');
39  slider = uicontrol(f,'Style','slider','Units','normalized',...
40  'Position',[di+textwidth+di, di ,1-3*di-textwidth,...
41  textheight],'Tag','slider1',...
42  'Callback','plot_data_sequence([],[],[],[],gcbf,gcbo);');
43  ax = axes('Units','normalized',...
44  'Position',[di,2*di+textheight,1-2*di,1-3*di - textheight],...
45  'Tag','axes1');
46  % cb = colorbar;
47  ud = [];
48  ud.model = varargin{1};
49  ud.grid = varargin{2};
50  ud.data = varargin{3};
51  ud.params = varargin{4};
52 
53  if isempty(ud.grid)
54  ud.grid = construct_grid(ud.params);
55  end;
56 
57  if isfield(ud.params,'title')
58  set(f,'Name',ud.params.title);
59  end;
60 
61  if ~isfield(ud.params,'clim_tight')
62  ud.params.clim_tight = 0;
63  end;
64 
65  if isfield(ud.params,'clim') && ud.params.clim_tight
66  error('please only specify one of the parameters clim and clim_tight.');
67  end;
68 
69  if ~isfield(ud.params,'clim') && ~ud.params.clim_tight
70  ud.params.clim = [min(min(ud.data)), max(max(ud.data))];
71  if ud.params.clim(1) == ud.params.clim(2)
72  ud.params.clim = ud.params.clim + [-eps, +eps];
73  end;
74  end;
75  set(f,'Userdata',ud);
76 
77  sl = findobj(f,'Tag','slider1');
78  %set(sl,'min',0);
79  %set(sl,'max',ud.params.nt);
80  %set(sl,'sliderstep',[1/ud.params.nt,1]);
81  set(sl,'min',1);
82  if size(ud.data,2)>1
83  set(sl,'max',size(ud.data,2));
84  set(sl,'sliderstep',[1/(size(ud.data,2)-1),1]);
85  else
86  set(sl,'max',size(ud.data,2)+eps);
87  set(sl,'visible','off');
88  % set(sl,'sliderstep',[0,0]);
89  end;
90  set(sl,'value',1);
91  th = findobj(f,'Tag','text1');
92  set(th,'String',('data slice 1') );
93  replot(f,sl,1);
94  % set(f,'Resize','on');
95 end;
96 
97 if nargin >=5 % callback-function
98 % disp('entered plot_data_sequence_callback...')
99  cbf = varargin{5};
100  cbo = varargin{6};
101  % disp('performing callback call of plot_fv_data')
102  th = findobj(gcbf,'Tag','text1');
103  v = round(get(gcbo,'value'));
104  set(gcbo,'value',v);
105  set(th,'String',['data slice ',num2str(v)]);
106  replot(gcbf,gcbo,v);
107 % disp('exiting plot_data_sequence_callback...')
108 end;
109 
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 function replot(fh,oh,v)
112 %disp('entered replot...')
113 ud = get(fh,'Userdata');
114 %if (size(ud.data,2)<v+1)
115 % disp('number of timesteps in U does not match paramt.nt');
116 %else
117 % d = reshape(ud.data(:,v+1),ud.params.nx,ud.params.ny)';
118 
119 %d = reshape(ud.data(:,v),ud.params.nx,ud.params.ny)';
120 %xr = ud.params.xrange;
121 %x = xr(1):(xr(2)-xr(1))/(ud.params.nx):xr(2);
122 %yr = ud.params.yrange;
123 %y = yr(1):(yr(2)-yr(1))/(ud.params.ny):yr(2);
124 %p=pcolor(x,y,[d,zeros(size(d,1),1);zeros(1,size(d,2)+1)]);
125 %if isfield(ud.params,'no_lines')
126 % % disp('halt in plot_p1_data');
127 % % keyboard;
128 % if ud.params.no_lines == 1
129 % set(p,'linestyle','None');
130 % end;
131 %end;
132 %ax = gca;
133 %axis equal;
134 %axis tight;
135 
136 d = ud.data(:,v);
137 
138 % if clim_tight, adapt color-range:
139 if ud.params.clim_tight
140  ud.params.clim = [min(min(d)), max(max(d))];
141  if ud.params.clim(1) == ud.params.clim(2)
142  ud.params.clim = ud.params.clim + [-eps, +eps];
143  end;
144 end;
145 
146 % delete old data:
147 ax = findobj(fh,'Tag','axes1');
148 cla(ax);
149 
150 %set(ax,'children',[]);
151 
152 feval(ud.params.plot_function,ud.grid,d,ud.params);
153 
154 %disp('after plot...')
155 %keyboard;
156 
157 set(gca,'Clim',[ud.params.clim(1), ud.params.clim(2)]);
158 
159 %ax2 = ax;
160 %if isfield(ud.params,'show_colorbar') & (ud.params.show_colorbar)
161 % if isfield(ud.params,'colorbar_mode')
162 % colorbar(ud.params.colorbar_mode);
163 % else
164 % colorbar;
165 % end;
166 % ax2 = gca;
167 %end;
168 
169 %if isfield(ud.params,'no_lines') & (ud.params.no_lines)
170 % set(p,'LineStyle','None');
171 %end;
172 %| \docupdate
173 %disp('exiting replot...')