1 | %'plot_field': plot any field with the structure defined in the uvmat package
|
---|
2 | %------------------------------------------------------------------------
|
---|
3 | %
|
---|
4 | % This function is used by uvmat to plot fields. It automatically chooses the representation
|
---|
5 | % appropriate to the input field structure:
|
---|
6 | % 2D vector fields are represented by arrows, 2D scalar fields by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).
|
---|
7 | % The input field structure is first tested by check_field_structure.m,
|
---|
8 | % then split into blocks of related variables by find_field_indices.m.
|
---|
9 | % The dimensionality of each block is obtained by this function
|
---|
10 | % considering the presence of variables with the attribute .Role='coord_x'
|
---|
11 | % and/or coord_y and/or coord_z (case of unstructured coordinates), or
|
---|
12 | % dimension variables (case of matrices).
|
---|
13 | %
|
---|
14 | % function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,htext,PosColorbar)
|
---|
15 | %
|
---|
16 | % OUPUT:
|
---|
17 | % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
|
---|
18 | % PlotParamOut: structure, representing the updated plotting parameters, in case of automatic scaling
|
---|
19 | % haxes: handle of the plotting axis, when a new figure is created.
|
---|
20 | %
|
---|
21 | %INPUT
|
---|
22 | % Data: structure describing the field to plot
|
---|
23 | % (optional) .ListGlobalAttribute: cell listing the names of the global attributes
|
---|
24 | % .Att_1,Att_2... : values of the global attributes
|
---|
25 | % (requested) .ListVarName: list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} )
|
---|
26 | % (requested) .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)
|
---|
27 | % .VarAttribute: cell of attributes for each element of .ListVarName (cell array of structures of the form VarAtt.key=value)
|
---|
28 | % (requested) .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
|
---|
29 | %
|
---|
30 | % Variable attribute .Role :
|
---|
31 | % The only variable attribute used for plotting purpose is .Role which can take
|
---|
32 | % the values
|
---|
33 | % Role = 'scalar': (default) represents a scalar field
|
---|
34 | % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
|
---|
35 | % unstructured coordinate x, y or z
|
---|
36 | % = 'vector': represents a vector field whose number of components
|
---|
37 | % is given by the last dimension (called 'nb_dim')
|
---|
38 | % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
|
---|
39 | % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
|
---|
40 | % = 'errorflag': provides an error flag marking false data,
|
---|
41 | % default=0, no error. Different non zero values can represent different criteria of elimination.
|
---|
42 | %
|
---|
43 | %
|
---|
44 | % additional elements characterizing the projection object (should not be necessary)--
|
---|
45 | % Data.Style : style of projection object
|
---|
46 | % Data.XObject,.YObject: set of coordinates defining the object position;
|
---|
47 | % Data.ProjMode=type of projection ;
|
---|
48 | % Data.ProjAngle=angle of projection;
|
---|
49 | % Data.DX,.DY,.DZ=increments;
|
---|
50 | % Data.MaxY,MinY: min and max Y
|
---|
51 |
|
---|
52 | % haxes: handle of the plotting axes to update with the new plot. If this input is absent or not a valid axes handle, a new figure is created.
|
---|
53 | %
|
---|
54 | % PlotParam: structure containing the parameters for plotting, as read on the uvmat or view_field GUI (by function 'read_GUI.m').
|
---|
55 | % Contains three substructures:
|
---|
56 | % .Coordinates: coordinate parameters:
|
---|
57 | % .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
|
---|
58 | % .Coordinates.CheckFixEqual: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.
|
---|
59 | % --scalars--
|
---|
60 | % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
|
---|
61 | % .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default
|
---|
62 | % .Scalar.CheckFixScal: =0 (default) lower and upper bounds of the scalar representation set to the min and max of the field
|
---|
63 | % =1 lower and upper bound imposed by .AMax and .MinA
|
---|
64 | % .Scalar.CheckBW= 1 black and white representation imposed, =0 by default.
|
---|
65 | % .Scalar.CheckContours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default
|
---|
66 | % .IncrA : contour interval
|
---|
67 | % -- vectors--
|
---|
68 | % .Vectors.VecScale: scale for the vector representation
|
---|
69 | % .Vectors.CheckFixVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale
|
---|
70 | % .Vectors.CheckHideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;
|
---|
71 | % .Vectors.CheckHideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;
|
---|
72 | % .Vectors.CheckDecimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate
|
---|
73 | % -- vector color--
|
---|
74 | % .Vectors.ColorCode= 'black','white': imposed color (default ='blue')
|
---|
75 | % 'rgb', : three colors red, blue, green depending
|
---|
76 | % on thresholds .colcode1 and .colcode2 on the input scalar value (C)
|
---|
77 | % 'brg': like rgb but reversed color order (blue, green, red)
|
---|
78 | % '64 colors': continuous color from blue to red (multijet)
|
---|
79 | % .Vectors.colcode1 : first threshold for rgb, first value for'continuous'
|
---|
80 | % .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous'
|
---|
81 | % .Vectors.CheckFixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC
|
---|
82 | % .Vectors.MinC = imposed minimum of the scalar field used for vector color;
|
---|
83 | % .Vectors.MaxC = imposed maximum of the scalar field used for vector color;
|
---|
84 | %
|
---|
85 | % PosColorbar: if not empty, display a colorbar for B&W images
|
---|
86 | % imposed position of the colorbar (ex [0.821 0.471 0.019 0.445])
|
---|
87 |
|
---|
88 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
89 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
|
---|
90 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
91 | % This file is part of the toolbox UVMAT.
|
---|
92 | %
|
---|
93 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
94 | % it under the terms of the GNU General Public License as published by
|
---|
95 | % the Free Software Foundation; either version 2 of the License, or
|
---|
96 | % (at your option) any later version.
|
---|
97 | %
|
---|
98 | % UVMAT is distributed in the hope that it will be useful,
|
---|
99 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
100 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
101 | % GNU General Public License (file UVMAT/COPYING.txt) for more details.
|
---|
102 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
103 |
|
---|
104 | function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
|
---|
105 | % use htext: handles of the text edit box (uicontrol)
|
---|
106 | % introduce PlotParam.Hold: 'on' or 'off' (for curves)
|
---|
107 | %default output
|
---|
108 |
|
---|
109 | if ~exist('PlotParam','var'),PlotParam=[];end;
|
---|
110 | if ~exist('PosColorbar','var'),PosColorbar=[];end;
|
---|
111 | PlotType='text'; %default
|
---|
112 | PlotParamOut=PlotParam;%default
|
---|
113 | Coordinates=[];
|
---|
114 | if isfield(PlotParam,'Coordinates')
|
---|
115 | Coordinates=PlotParam.Coordinates;
|
---|
116 | end
|
---|
117 |
|
---|
118 | %% test axes and figure
|
---|
119 | testnewfig=1;%test to create a new figure (default)
|
---|
120 | testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
|
---|
121 | if exist('haxes','var')
|
---|
122 | if ishandle(haxes)
|
---|
123 | if isequal(get(haxes,'Type'),'axes')
|
---|
124 | testnewfig=0;
|
---|
125 | AxeData=get(haxes,'UserData');
|
---|
126 | if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)
|
---|
127 | if isequal(get(AxeData.ZoomAxes,'Type'),'axes')
|
---|
128 | testzoomaxes=1;
|
---|
129 | zoomaxes=AxeData.ZoomAxes;
|
---|
130 | end
|
---|
131 | end
|
---|
132 | end
|
---|
133 | end
|
---|
134 | end
|
---|
135 |
|
---|
136 | % create a new figure and axes if the plotting axes does not exist
|
---|
137 | if testnewfig
|
---|
138 | hfig=figure;
|
---|
139 | set(hfig,'Units','normalized')
|
---|
140 | haxes=axes;
|
---|
141 | set(haxes,'position',[0.13,0.2,0.775,0.73])
|
---|
142 | PlotParam.NextPlot='add'; %parameter for plot_profile and plot_his
|
---|
143 | else
|
---|
144 | hfig=get(haxes,'parent');
|
---|
145 | set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
|
---|
146 | set(hfig,'CurrentAxes',haxes)% haxes becomes the current axes of the parent figure
|
---|
147 | end
|
---|
148 |
|
---|
149 | %% check input structure
|
---|
150 | if ~isempty(Data)
|
---|
151 | [Data,errormsg]=check_field_structure(Data);
|
---|
152 | if ~isempty(errormsg)
|
---|
153 | msgbox_uvmat('ERROR',['input of plot_field/check_field_structure: ' errormsg])
|
---|
154 | display(['input of plot_field/check_field_structure:: ' errormsg])
|
---|
155 | return
|
---|
156 | end
|
---|
157 |
|
---|
158 | %% check the cells of fields :
|
---|
159 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
|
---|
160 | if ~isempty(errormsg)
|
---|
161 | msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg]);
|
---|
162 | return
|
---|
163 | end
|
---|
164 | index_2D=find(NbDim==2,2);%find 2D fields (at most 2)
|
---|
165 | index_3D=find(NbDim>2,1);
|
---|
166 | if ~isempty(index_3D)
|
---|
167 | if isfield(Data,'NbDim')&& isequal(Data.NbDim,2)
|
---|
168 | index_2D=[index_2D index_3D];
|
---|
169 | else
|
---|
170 | msgbox_uvmat('ERROR','volume plot not implemented yet');
|
---|
171 | return
|
---|
172 | end
|
---|
173 | end
|
---|
174 |
|
---|
175 | index_1D=find(NbDim==1);
|
---|
176 | index_0D=find(NbDim==0);
|
---|
177 |
|
---|
178 | %% set axes properties
|
---|
179 | if isfield(Coordinates,'CheckFixLimits') && isequal(Coordinates.CheckFixLimits,1) %adjust the graph limits*
|
---|
180 | set(haxes,'XLimMode', 'manual')
|
---|
181 | set(haxes,'YLimMode', 'manual')
|
---|
182 | else
|
---|
183 | set(haxes,'XLimMode', 'auto')
|
---|
184 | set(haxes,'YLimMode', 'auto')
|
---|
185 | end
|
---|
186 | if ~isfield(Coordinates,'CheckFixEqual')&& isfield(Data,'CoordUnit')
|
---|
187 | Coordinates.CheckFixEqual=1;
|
---|
188 | end
|
---|
189 | if isfield(Coordinates,'CheckFixEqual') && isequal(Coordinates.CheckFixEqual,1)
|
---|
190 | set(haxes,'DataAspectRatioMode','manual')
|
---|
191 | set(haxes,'DataAspectRatio',[1 1 1])
|
---|
192 | else
|
---|
193 | set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
|
---|
194 | end
|
---|
195 | else
|
---|
196 | index_2D=[];
|
---|
197 | index_1D=[];
|
---|
198 | index_0D=[];
|
---|
199 | end
|
---|
200 |
|
---|
201 | %% plot if the input field is valid
|
---|
202 | PlotType='text';
|
---|
203 | errormsg=[];
|
---|
204 | AxeData=get(haxes,'UserData');
|
---|
205 | if isempty(index_2D)
|
---|
206 | plot_plane([],[],[],haxes);%removes images or vector plots if any
|
---|
207 | else
|
---|
208 | [xx,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
|
---|
209 | AxeData.NbDim=2;
|
---|
210 | if testzoomaxes && isempty(errormsg)
|
---|
211 | [zoomaxes,PlotParamOut,xx,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
|
---|
212 | AxeData.ZoomAxes=zoomaxes;
|
---|
213 | end
|
---|
214 | %remove coordinates variables from 1D plot
|
---|
215 | for ivar=1:length(index_1D)
|
---|
216 | if isequal(CellVarIndex{index_1D(ivar)},VarType{index_1D(ivar)}.coord)
|
---|
217 | index_1D(ivar)=0;
|
---|
218 | end
|
---|
219 | end
|
---|
220 | index_1D=find(index_1D);
|
---|
221 | end
|
---|
222 |
|
---|
223 | if isempty(index_1D)
|
---|
224 | plot_profile([],[],[],haxes);%
|
---|
225 | else
|
---|
226 | Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,Coordinates);%
|
---|
227 | if testzoomaxes
|
---|
228 | [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);
|
---|
229 | AxeData.ZoomAxes=zoomaxes;
|
---|
230 | end
|
---|
231 | if ~isempty(Coordinates)
|
---|
232 | PlotParamOut.Coordinates=Coordinates;
|
---|
233 | end
|
---|
234 | PlotType='line';
|
---|
235 | end
|
---|
236 | htext=findobj(hfig,'Tag','text_display');
|
---|
237 | if ~isempty(htext)
|
---|
238 | if isempty(index_0D)
|
---|
239 | set(htext,'String',{''})
|
---|
240 | else
|
---|
241 | [errormsg]=plot_text(Data,CellVarIndex(index_0D),htext);
|
---|
242 | end
|
---|
243 | end
|
---|
244 |
|
---|
245 | if ~isempty(errormsg)
|
---|
246 | msgbox_uvmat('ERROR', errormsg)
|
---|
247 | end
|
---|
248 | if isfield(PlotParamOut,'MinX')
|
---|
249 | AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX];
|
---|
250 | AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];%[PlotParamOut.MinY PlotParamOut.MaxY]
|
---|
251 | end
|
---|
252 |
|
---|
253 | %% update the parameters stored in AxeData
|
---|
254 | set(haxes,'UserData',AxeData)
|
---|
255 |
|
---|
256 | %% update the plotted field stored in parent figure
|
---|
257 | FigData=get(hfig,'UserData');
|
---|
258 | tagaxes=get(haxes,'tag');
|
---|
259 | if isfield(FigData,tagaxes)
|
---|
260 | eval(['FigData.' tagaxes '=Data;'])
|
---|
261 | set(hfig,'UserData',FigData)
|
---|
262 | end
|
---|
263 |
|
---|
264 | %-------------------------------------------------------------------
|
---|
265 | function errormsg=plot_text(FieldData,CellVarIndex,htext)
|
---|
266 | %-------------------------------------------------------------------
|
---|
267 | errormsg=[];
|
---|
268 | txt_cell={};
|
---|
269 | for icell=1:length(CellVarIndex)
|
---|
270 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName
|
---|
271 | for ivar=1:length(VarIndex)
|
---|
272 | VarName=FieldData.ListVarName{VarIndex(ivar)};
|
---|
273 | VarValue=FieldData.(VarName);
|
---|
274 | if size(VarValue,1)~=1
|
---|
275 | VarValue=VarValue';
|
---|
276 | end
|
---|
277 | txt=[VarName '=' num2str(VarValue)];
|
---|
278 | txt_cell=[txt_cell;{txt}];
|
---|
279 | end
|
---|
280 | end
|
---|
281 | set(htext,'String',txt_cell)
|
---|
282 | set(htext,'UserData',txt_cell)% for storage during mouse display
|
---|
283 |
|
---|
284 | %-------------------------------------------------------------------
|
---|
285 | function CoordinatesOut=plot_profile(data,CellVarIndex,VarType,haxes,Coordinates)
|
---|
286 | %-------------------------------------------------------------------
|
---|
287 |
|
---|
288 | if ~exist('Coordinates','var')
|
---|
289 | Coordinates=[];
|
---|
290 | end
|
---|
291 | CoordinatesOut=Coordinates; %default
|
---|
292 | hfig=get(haxes,'parent');
|
---|
293 | %suppress existing plot isf empty data
|
---|
294 | if isempty(data)
|
---|
295 | hplot=findobj(haxes,'tag','plot_line');
|
---|
296 | if ~isempty(hplot)
|
---|
297 | delete(hplot)
|
---|
298 | end
|
---|
299 | hlegend=findobj(hfig,'tag','legend');
|
---|
300 | if ~isempty(hlegend)
|
---|
301 | delete(hlegend)
|
---|
302 | end
|
---|
303 | return
|
---|
304 | end
|
---|
305 |
|
---|
306 | ColorOrder=[1 0 0;0 0.5 0;0 0 1;0 0.75 0.75;0.75 0 0.75;0.75 0.75 0;0.25 0.25 0.25];
|
---|
307 | set(haxes,'ColorOrder',ColorOrder)
|
---|
308 | if isfield(Coordinates,'NextPlot')
|
---|
309 | set(haxes,'NextPlot',Coordinates.NextPlot)
|
---|
310 | end
|
---|
311 | % adjust the size of the plot to include the whole field,
|
---|
312 |
|
---|
313 | legend_str={};
|
---|
314 |
|
---|
315 | %% prepare the string for plot command
|
---|
316 | plotstr='hhh=plot(';
|
---|
317 | coord_x_index=[];
|
---|
318 | xtitle='';
|
---|
319 | ytitle='';
|
---|
320 | test_newplot=1;
|
---|
321 |
|
---|
322 | %loop on input fields
|
---|
323 | for icell=1:length(CellVarIndex)
|
---|
324 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName
|
---|
325 | if ~isempty(VarType{icell}.coord_x)
|
---|
326 | coord_x_index=VarType{icell}.coord_x;
|
---|
327 | else
|
---|
328 | coord_x_index_cell=VarType{icell}.coord(1);
|
---|
329 | if isequal(coord_x_index_cell,0)
|
---|
330 | continue % the cell has no abscissa, skip it
|
---|
331 | end
|
---|
332 | coord_x_index=coord_x_index_cell;
|
---|
333 | end
|
---|
334 | testplot=ones(size(data.ListVarName));%default test for plotted variables
|
---|
335 | xtitle=[xtitle data.ListVarName{coord_x_index}];
|
---|
336 | eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
|
---|
337 | if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=coord_x_index && isfield(data.VarAttribute{coord_x_index},'units')
|
---|
338 | xtitle=[xtitle '(' data.VarAttribute{coord_x_index}.units '), '];
|
---|
339 | else
|
---|
340 | xtitle=[xtitle ', '];
|
---|
341 | end
|
---|
342 | eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
|
---|
343 | XMin(icell)=min(coord_x{icell});
|
---|
344 | XMax(icell)=max(coord_x{icell});
|
---|
345 | testplot(coord_x_index)=0;
|
---|
346 | if ~isempty(VarType{icell}.ancillary')
|
---|
347 | testplot(VarType{icell}.ancillary)=0;
|
---|
348 | end
|
---|
349 | if ~isempty(VarType{icell}.warnflag')
|
---|
350 | testplot(VarType{icell}.warnflag)=0;
|
---|
351 | end
|
---|
352 | if isfield(data,'VarAttribute')
|
---|
353 | VarAttribute=data.VarAttribute;
|
---|
354 | for ivar=1:length(VarIndex)
|
---|
355 | if length(VarAttribute)>=VarIndex(ivar) && isfield(VarAttribute{VarIndex(ivar)},'long_name')
|
---|
356 | plotname{VarIndex(ivar)}=VarAttribute{VarIndex(ivar)}.long_name;
|
---|
357 | else
|
---|
358 | plotname{VarIndex(ivar)}=data.ListVarName{VarIndex(ivar)};%name for display in plot A METTRE
|
---|
359 | end
|
---|
360 | end
|
---|
361 | end
|
---|
362 | if ~isempty(VarType{icell}.discrete')
|
---|
363 | charplot_0='''+''';
|
---|
364 | else
|
---|
365 | charplot_0='''-''';
|
---|
366 | end
|
---|
367 | YMin=0;
|
---|
368 | YMax=1;%default
|
---|
369 | for ivar=1:length(VarIndex)
|
---|
370 | if testplot(VarIndex(ivar))
|
---|
371 | VarName=data.ListVarName{VarIndex(ivar)};
|
---|
372 | ytitle=[ytitle VarName];
|
---|
373 | if isfield(data,'VarAttribute')&& numel(data.VarAttribute)>=VarIndex(ivar) && isfield(data.VarAttribute{VarIndex(ivar)},'units')
|
---|
374 | ytitle=[ytitle '(' data.VarAttribute{VarIndex(ivar)}.units '), '];
|
---|
375 | else
|
---|
376 | ytitle=[ytitle ', '];
|
---|
377 | end
|
---|
378 | eval(['data.' VarName '=squeeze(data.' VarName ');'])
|
---|
379 | %eval(['min(data.' VarName ')'])
|
---|
380 | YMin(ivar)=min(min(data.(VarName)));
|
---|
381 | YMax(ivar)=max(max(data.(VarName)));
|
---|
382 | plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot_0 ','];
|
---|
383 | eval(['nbcomponent2=size(data.' VarName ',2);']);
|
---|
384 | eval(['nbcomponent1=size(data.' VarName ',1);']);
|
---|
385 | if numel(coord_x{icell})==2
|
---|
386 | coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
|
---|
387 | end
|
---|
388 | if nbcomponent1==1|| nbcomponent2==1
|
---|
389 | legend_str=[legend_str {VarName}]; %variable with one component
|
---|
390 | else %variable with severals components
|
---|
391 | for ic=1:min(nbcomponent1,nbcomponent2)
|
---|
392 | legend_str=[legend_str [VarName '_' num2str(ic)]]; %variable with severals components
|
---|
393 | end % labeled by their index (e.g. color component)
|
---|
394 | end
|
---|
395 | end
|
---|
396 | end
|
---|
397 | YMin_cell(icell)=min(YMin);
|
---|
398 | YMax_cell(icell)=max(YMax);
|
---|
399 | end
|
---|
400 |
|
---|
401 | %% activate the plot
|
---|
402 | if test_newplot && ~isequal(plotstr,'hhh=plot(')
|
---|
403 | set(hfig,'CurrentAxes',haxes)
|
---|
404 | tag=get(haxes,'tag');
|
---|
405 | %%%
|
---|
406 | plotstr=[plotstr '''tag'',''plot_line'');'];
|
---|
407 | eval(plotstr) %execute plot (instruction plotstr)
|
---|
408 | %%%
|
---|
409 | set(haxes,'tag',tag)
|
---|
410 | grid(haxes, 'on')
|
---|
411 | hxlabel=xlabel(xtitle(1:end-2));% xlabel (removes ', ' at the end)
|
---|
412 | set(hxlabel,'Interpreter','none')% desable tex interpreter
|
---|
413 | if length(legend_str)>=1
|
---|
414 | hylabel=ylabel(ytitle(1:end-2));% ylabel (removes ', ' at the end)
|
---|
415 | set(hylabel,'Interpreter','none')% desable tex interpreter
|
---|
416 | end
|
---|
417 | if ~isempty(legend_str)
|
---|
418 | hlegend=findobj(hfig,'Tag','legend');
|
---|
419 | if isempty(hlegend)
|
---|
420 | hlegend=legend(legend_str);
|
---|
421 | txt=ver('MATLAB');
|
---|
422 | Release=txt.Release;
|
---|
423 | relnumb=str2double(Release(3:4));% should be changed to Version for better compatibility
|
---|
424 | if relnumb >= 14
|
---|
425 | set(hlegend,'Interpreter','none')% desable tex interpreter
|
---|
426 | end
|
---|
427 | else
|
---|
428 | legend_old=get(hlegend,'String');
|
---|
429 | if isequal(size(legend_old,1),size(legend_str,1))&&~isequal(legend_old,legend_str)
|
---|
430 | set(hlegend,'String',[legend_old legend_str]);
|
---|
431 | end
|
---|
432 | end
|
---|
433 | end
|
---|
434 | title_str='';
|
---|
435 | if isfield(data,'filename')
|
---|
436 | [Path, title_str, ext]=fileparts(data.filename);
|
---|
437 | title_str=[title_str ext];
|
---|
438 | end
|
---|
439 | if isfield(data,'Action')
|
---|
440 | if ~isequal(title_str,'')
|
---|
441 | title_str=[title_str ', '];
|
---|
442 | end
|
---|
443 | title_str=[title_str data.Action];
|
---|
444 | end
|
---|
445 | htitle=title(title_str);
|
---|
446 | txt=ver('MATLAB');
|
---|
447 | Release=txt.Release;
|
---|
448 | relnumb=str2double(Release(3:4));
|
---|
449 | if relnumb >= 14
|
---|
450 | set(htitle,'Interpreter','none')% desable tex interpreter
|
---|
451 | end
|
---|
452 | end
|
---|
453 |
|
---|
454 | %% determine axes bounds
|
---|
455 | %CoordinatesOut.RangeX=[min(XMin) max(XMax)];
|
---|
456 | %CoordinatesOut.RangeY=[min(YMin_cell) max(YMax_cell)];
|
---|
457 | fix_lim=isfield(Coordinates,'CheckFixLimits') && Coordinates.CheckFixLimits;
|
---|
458 | if fix_lim
|
---|
459 | if ~isfield(Coordinates,'MinX')||~isfield(Coordinates,'MaxX')||~isfield(Coordinates,'MinY')||~isfield(Coordinates,'MaxY')
|
---|
460 | fix_lim=0; %free limits if lits are not set,
|
---|
461 | end
|
---|
462 | end
|
---|
463 | if fix_lim
|
---|
464 | set(haxes,'XLim',[Coordinates.MinX Coordinates.MaxX])
|
---|
465 | set(haxes,'YLim',[Coordinates.MinY Coordinates.MaxY])
|
---|
466 | else
|
---|
467 | CoordinatesOut.MinX=min(XMin);
|
---|
468 | CoordinatesOut.MaxX=max(XMax);
|
---|
469 | CoordinatesOut.MinY=min(YMin_cell);
|
---|
470 | CoordinatesOut.MaxY=max(YMax_cell);
|
---|
471 | end
|
---|
472 |
|
---|
473 | %-------------------------------------------------------------------
|
---|
474 | function [haxes,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex,VarTypeCell,haxes,PlotParam,PosColorbar)
|
---|
475 | %-------------------------------------------------------------------
|
---|
476 | grid(haxes, 'off')
|
---|
477 | %default plotting parameters
|
---|
478 | PlotType='plane';%default
|
---|
479 | if ~exist('PlotParam','var')
|
---|
480 | PlotParam=[];
|
---|
481 | end
|
---|
482 | if ~isfield(PlotParam,'Scalar')
|
---|
483 | PlotParam.Scalar=[];
|
---|
484 | end
|
---|
485 | if ~isfield(PlotParam,'Vectors')
|
---|
486 | PlotParam.Vectors=[];
|
---|
487 | end
|
---|
488 |
|
---|
489 | PlotParamOut=PlotParam;%default
|
---|
490 | hfig=get(haxes,'parent');
|
---|
491 | hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
|
---|
492 | hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
|
---|
493 | errormsg='';%default
|
---|
494 | test_ima=0; %default: test for image or map plot
|
---|
495 | test_vec=0; %default: test for vector plots
|
---|
496 | test_black=0;
|
---|
497 | test_false=0;
|
---|
498 | test_C=0;
|
---|
499 | XName='';
|
---|
500 | x_units='';
|
---|
501 | YName='';
|
---|
502 | y_units='';
|
---|
503 | for icell=1:length(CellVarIndex) % length(CellVarIndex) =1 or 2 (from the calling function)
|
---|
504 | VarType=VarTypeCell{icell};
|
---|
505 | ivar_X=VarType.coord_x; % defines (unique) index for the variable representing unstructured x coordinate (default =[])
|
---|
506 | ivar_Y=VarType.coord_y; % defines (unique)index for the variable representing unstructured y coordinate (default =[])
|
---|
507 | ivar_U=VarType.vector_x; % defines (unique) index for the variable representing x vector component (default =[])
|
---|
508 | ivar_V=VarType.vector_y; % defines (unique) index for the variable representing y vector component (default =[])
|
---|
509 | ivar_C=[VarType.scalar VarType.image VarType.color VarType.ancillary]; %defines index (indices) for the scalar or ancillary fields
|
---|
510 | if numel(ivar_C)>1
|
---|
511 | errormsg= 'error in plot_field: too many scalar inputs';
|
---|
512 | return
|
---|
513 | end
|
---|
514 | ivar_F=VarType.warnflag; %defines index (unique) for warning flag variable
|
---|
515 | ivar_FF=VarType.errorflag; %defines index (unique) for error flag variable
|
---|
516 | ind_coord=find(VarType.coord);
|
---|
517 | if numel(ind_coord)==2
|
---|
518 | VarType.coord=VarType.coord(ind_coord);
|
---|
519 | end
|
---|
520 | if ~isempty(ivar_U) && ~isempty(ivar_V)% vector components detected
|
---|
521 | if test_vec
|
---|
522 | errormsg='error in plot_field: attempt to plot two vector fields';
|
---|
523 | return
|
---|
524 | else
|
---|
525 | test_vec=1;
|
---|
526 | vec_U=Data.(Data.ListVarName{ivar_U});
|
---|
527 | vec_V=Data.(Data.ListVarName{ivar_V});
|
---|
528 | if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates or structured ones (then ivar_X and ivar_Y empty)
|
---|
529 | XName=Data.ListVarName{ivar_X};
|
---|
530 | YName=Data.ListVarName{ivar_Y};
|
---|
531 | eval(['vec_X=reshape(Data.' XName ',[],1);'])
|
---|
532 | eval(['vec_Y=reshape(Data.' YName ',[],1);'])
|
---|
533 | elseif numel(VarType.coord)==2 && ~isequal(VarType.coord,[0 0]);%coordinates defines by dimension variables
|
---|
534 | eval(['y=Data.' Data.ListVarName{VarType.coord(1)} ';'])
|
---|
535 | eval(['x=Data.' Data.ListVarName{VarType.coord(2)} ';'])
|
---|
536 | if numel(y)==2 % y defined by first and last values on aregular mesh
|
---|
537 | y=linspace(y(1),y(2),size(vec_U,1));
|
---|
538 | end
|
---|
539 | if numel(x)==2 % y defined by first and last values on aregular mesh
|
---|
540 | x=linspace(x(1),x(2),size(vec_U,2));
|
---|
541 | end
|
---|
542 | [vec_X,vec_Y]=meshgrid(x,y);
|
---|
543 | else
|
---|
544 | errormsg='error in plot_field: invalid coordinate definition for vector field';
|
---|
545 | return
|
---|
546 | end
|
---|
547 | if ~isempty(ivar_C)
|
---|
548 | eval(['vec_C=Data.' Data.ListVarName{ivar_C} ';']) ;
|
---|
549 | vec_C=reshape(vec_C,1,numel(vec_C));
|
---|
550 | test_C=1;
|
---|
551 | end
|
---|
552 | if ~isempty(ivar_F)%~(isfield(PlotParam.Vectors,'HideWarning')&& isequal(PlotParam.Vectors.HideWarning,1))
|
---|
553 | if test_vec
|
---|
554 | vec_F=Data.(Data.ListVarName{ivar_F}); % warning flags for dubious vectors
|
---|
555 | if ~(isfield(PlotParam.Vectors,'CheckHideWarning') && isequal(PlotParam.Vectors.CheckHideWarning,1))
|
---|
556 | test_black=1;
|
---|
557 | end
|
---|
558 | end
|
---|
559 | end
|
---|
560 | if ~isempty(ivar_FF) %&& ~test_false
|
---|
561 | if test_vec% TODO: deal with FF for structured coordinates
|
---|
562 | vec_FF=Data.(Data.ListVarName{ivar_FF}); % flags for false vectors
|
---|
563 | end
|
---|
564 | end
|
---|
565 | end
|
---|
566 | elseif ~isempty(ivar_C) %scalar or image
|
---|
567 | if test_ima
|
---|
568 | errormsg='attempt to plot two scalar fields or images';
|
---|
569 | return
|
---|
570 | end
|
---|
571 | eval(['A=squeeze(Data.' Data.ListVarName{ivar_C} ');']) ;% scalar represented as color image
|
---|
572 | test_ima=1;
|
---|
573 | if ~isempty(ivar_X) && ~isempty(ivar_Y)% 2D field (with unstructured coordinates (then ivar_X and ivar_Y not empty)
|
---|
574 | A=reshape(A,1,[]);
|
---|
575 | XName=Data.ListVarName{ivar_X};
|
---|
576 | YName=Data.ListVarName{ivar_Y};
|
---|
577 | eval(['AX=reshape(Data.' XName ',1,[]);'])
|
---|
578 | eval(['AY=reshape(Data.' YName ',1,[]);'])
|
---|
579 | [A,AX,AY]=proj_grid(AX',AY',A',[],[],'np>256'); % interpolate on a grid
|
---|
580 | if isfield(Data,'VarAttribute')
|
---|
581 | if numel(Data.VarAttribute)>=ivar_X && isfield(Data.VarAttribute{ivar_X},'units')
|
---|
582 | x_units=[' (' Data.VarAttribute{ivar_X}.units ')'];
|
---|
583 | end
|
---|
584 | if numel(Data.VarAttribute)>=ivar_Y && isfield(Data.VarAttribute{ivar_Y},'units')
|
---|
585 | y_units=[' (' Data.VarAttribute{ivar_Y}.units ')'];
|
---|
586 | end
|
---|
587 | end
|
---|
588 | elseif numel(VarType.coord)==2 %structured coordinates
|
---|
589 | XName=Data.ListVarName{VarType.coord(2)};
|
---|
590 | YName=Data.ListVarName{VarType.coord(1)};
|
---|
591 | eval(['AY=Data.' Data.ListVarName{VarType.coord(1)} ';'])
|
---|
592 | eval(['AX=Data.' Data.ListVarName{VarType.coord(2)} ';'])
|
---|
593 | test_interp_X=0; %default, regularly meshed X coordinate
|
---|
594 | test_interp_Y=0; %default, regularly meshed Y coordinate
|
---|
595 | if isfield(Data,'VarAttribute')
|
---|
596 | if numel(Data.VarAttribute)>=VarType.coord(2) && isfield(Data.VarAttribute{VarType.coord(2)},'units')
|
---|
597 | x_units=Data.VarAttribute{VarType.coord(2)}.units;
|
---|
598 | end
|
---|
599 | if numel(Data.VarAttribute)>=VarType.coord(1) && isfield(Data.VarAttribute{VarType.coord(1)},'units')
|
---|
600 | y_units=Data.VarAttribute{VarType.coord(1)}.units;
|
---|
601 | end
|
---|
602 | end
|
---|
603 | if numel(AY)>2
|
---|
604 | DAY=diff(AY);
|
---|
605 | DAY_min=min(DAY);
|
---|
606 | DAY_max=max(DAY);
|
---|
607 | if sign(DAY_min)~=sign(DAY_max);% =1 for increasing values, 0 otherwise
|
---|
608 | errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarType.coord(1)} ];
|
---|
609 | return
|
---|
610 | end
|
---|
611 | test_interp_Y=(DAY_max-DAY_min)> 0.0001*abs(DAY_max);
|
---|
612 | end
|
---|
613 | if numel(AX)>2
|
---|
614 | DAX=diff(AX);
|
---|
615 | DAX_min=min(DAX);
|
---|
616 | DAX_max=max(DAX);
|
---|
617 | if sign(DAX_min)~=sign(DAX_max);% =1 for increasing values, 0 otherwise
|
---|
618 | errormsg=['errror in plot_field.m: non monotonic dimension variable ' Data.ListVarName{VarType.coord(2)} ];
|
---|
619 | return
|
---|
620 | end
|
---|
621 | test_interp_X=(DAX_max-DAX_min)> 0.0001*abs(DAX_max);
|
---|
622 | end
|
---|
623 | if test_interp_Y
|
---|
624 | npxy(1)=max([256 floor((AY(end)-AY(1))/DAY_min) floor((AY(end)-AY(1))/DAY_max)]);
|
---|
625 | yI=linspace(AY(1),AY(end),npxy(1));
|
---|
626 | if ~test_interp_X
|
---|
627 | xI=linspace(AX(1),AX(end),size(A,2));%default
|
---|
628 | AX=xI;
|
---|
629 | end
|
---|
630 | end
|
---|
631 | if test_interp_X
|
---|
632 | npxy(2)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
|
---|
633 | xI=linspace(AX(1),AX(end),npxy(2));
|
---|
634 | if ~test_interp_Y
|
---|
635 | yI=linspace(AY(1),AY(end),size(A,1));
|
---|
636 | AY=yI;
|
---|
637 | end
|
---|
638 | end
|
---|
639 | if test_interp_X || test_interp_Y
|
---|
640 | [AX2D,AY2D]=meshgrid(AX,AY);
|
---|
641 | A=interp2(AX2D,AY2D,double(A),xI,yI');
|
---|
642 | end
|
---|
643 | AX=[AX(1) AX(end)];% keep only the lower and upper bounds for image represnetation
|
---|
644 | AY=[AY(1) AY(end)];
|
---|
645 | else
|
---|
646 | errormsg='error in plot_field: invalid coordinate definition ';
|
---|
647 | return
|
---|
648 | end
|
---|
649 | end
|
---|
650 | %define coordinates as CoordUnits, if not defined as attribute for each variable
|
---|
651 | if isfield(Data,'CoordUnit')
|
---|
652 | if isempty(x_units)
|
---|
653 | x_units=Data.CoordUnit;
|
---|
654 | end
|
---|
655 | if isempty(y_units)
|
---|
656 | y_units=Data.CoordUnit;
|
---|
657 | end
|
---|
658 | end
|
---|
659 |
|
---|
660 | end
|
---|
661 |
|
---|
662 | %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
663 |
|
---|
664 | if isfield(PlotParam.Scalar,'ListContour')
|
---|
665 | CheckContour=strcmp(PlotParam.Scalar.ListContour{1},'contours');
|
---|
666 | else
|
---|
667 | CheckContour=0; %default
|
---|
668 | end
|
---|
669 | PlotParamOut=PlotParam; %default
|
---|
670 | if test_ima
|
---|
671 | % distinguish B/W and color images
|
---|
672 | np=size(A);%size of image
|
---|
673 | siz=numel(np);
|
---|
674 | if siz>3
|
---|
675 | errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];
|
---|
676 | return
|
---|
677 | end
|
---|
678 | if siz==3
|
---|
679 | if np(3)==1
|
---|
680 | siz=2;%B W image
|
---|
681 | elseif np(3)==3
|
---|
682 | siz=3;%color image
|
---|
683 | else
|
---|
684 | errormsg=['unrecognized scalar type in plot_field: considered as 2D field with ' num2str(np(3)) ' color components'];
|
---|
685 | return
|
---|
686 | end
|
---|
687 | end
|
---|
688 |
|
---|
689 | %set the color map
|
---|
690 | if isfield(PlotParam.Scalar,'CheckBW')
|
---|
691 | BW=PlotParam.Scalar.CheckBW; %test for BW gray scale images
|
---|
692 | else
|
---|
693 | BW=(siz==2) && (isa(A,'uint8')|| isa(A,'uint16'));% non color images represented in gray scale by default
|
---|
694 | end
|
---|
695 |
|
---|
696 | %case of grey level images or contour plot
|
---|
697 | if siz==2
|
---|
698 | if ~isfield(PlotParam.Scalar,'CheckFixScalar')
|
---|
699 | PlotParam.Scalar.CheckFixScalar=0;%default
|
---|
700 | end
|
---|
701 | if ~isfield(PlotParam.Scalar,'MinA')
|
---|
702 | PlotParam.Scalar.MinA=[];%default
|
---|
703 | end
|
---|
704 | if ~isfield(PlotParam.Scalar,'MaxA')
|
---|
705 | PlotParam.Scalar.MaxA=[];%default
|
---|
706 | end
|
---|
707 | Aline=[];
|
---|
708 | if ~PlotParam.Scalar.CheckFixScalar ||isempty(PlotParam.Scalar.MinA)||~isa(PlotParam.Scalar.MinA,'double') %correct if there is no numerical data in edit box
|
---|
709 | Aline=reshape(A,1,[]);
|
---|
710 | Aline=Aline(~isnan(A));
|
---|
711 | if isempty(Aline)
|
---|
712 | errormsg='NaN input scalar or image in plot_field';
|
---|
713 | return
|
---|
714 | end
|
---|
715 | MinA=double(min(Aline));
|
---|
716 | else
|
---|
717 | MinA=PlotParam.Scalar.MinA;
|
---|
718 | end;
|
---|
719 | if ~PlotParam.Scalar.CheckFixScalar||isempty(PlotParam.Scalar.MaxA)||~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
|
---|
720 | if isempty(Aline)
|
---|
721 | Aline=reshape(A,1,[]);
|
---|
722 | Aline=Aline(~isnan(A));
|
---|
723 | if isempty(Aline)
|
---|
724 | errormsg='NaN input scalar or image in plot_field';
|
---|
725 | return
|
---|
726 | end
|
---|
727 | end
|
---|
728 | MaxA=double(max(Aline));
|
---|
729 | else
|
---|
730 | MaxA=PlotParam.Scalar.MaxA;
|
---|
731 | end;
|
---|
732 | PlotParamOut.Scalar.MinA=MinA;
|
---|
733 | PlotParamOut.Scalar.MaxA=MaxA;
|
---|
734 | % case of contour plot
|
---|
735 | if CheckContour
|
---|
736 | if ~isempty(hima) && ishandle(hima)
|
---|
737 | delete(hima)
|
---|
738 | end
|
---|
739 | if ~isfield(PlotParam.Scalar,'IncrA')
|
---|
740 | PlotParam.Scalar.IncrA=NaN;
|
---|
741 | end
|
---|
742 | if isempty(PlotParam.Scalar.IncrA)|| isnan(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
|
---|
743 | cont=colbartick(MinA,MaxA);
|
---|
744 | intercont=cont(2)-cont(1);%default
|
---|
745 | PlotParamOut.Scalar.IncrA=intercont;
|
---|
746 | else
|
---|
747 | intercont=PlotParam.Scalar.IncrA;
|
---|
748 | end
|
---|
749 | B=A;
|
---|
750 | abscontmin=intercont*floor(MinA/intercont);
|
---|
751 | abscontmax=intercont*ceil(MaxA/intercont);
|
---|
752 | contmin=intercont*floor(min(min(B))/intercont);
|
---|
753 | contmax=intercont*ceil(max(max(B))/intercont);
|
---|
754 | cont_pos_plus=0:intercont:contmax;
|
---|
755 | cont_pos_min=double(contmin):intercont:-intercont;
|
---|
756 | cont_pos=[cont_pos_min cont_pos_plus];
|
---|
757 | sizpx=(AX(end)-AX(1))/(np(2)-1);
|
---|
758 | sizpy=(AY(1)-AY(end))/(np(1)-1);
|
---|
759 | x_cont=AX(1):sizpx:AX(end); % pixel x coordinates for image display
|
---|
760 | y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
|
---|
761 | % axes(haxes)% set the input axes handle as current axis
|
---|
762 | txt=ver('MATLAB');
|
---|
763 | Release=txt.Release;
|
---|
764 | relnumb=str2double(Release(3:4));
|
---|
765 | if relnumb >= 14
|
---|
766 | vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
|
---|
767 | map=[vec' vec' vec'];
|
---|
768 | colormap(map);
|
---|
769 | [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
|
---|
770 | set(hcontour,'Fill','on')
|
---|
771 | set(hcontour,'LineStyle','none')
|
---|
772 | hold on
|
---|
773 | end
|
---|
774 | [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
|
---|
775 | hold on
|
---|
776 | [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
|
---|
777 | set(hcontour_m,'LineColor',[1 1 1])
|
---|
778 | hold off
|
---|
779 | caxis([abscontmin abscontmax])
|
---|
780 | colormap(map);
|
---|
781 | end
|
---|
782 |
|
---|
783 | % set colormap for image display
|
---|
784 | if ~CheckContour
|
---|
785 | % rescale the grey levels with min and max, put a grey scale colorbar
|
---|
786 | B=A;
|
---|
787 | if BW
|
---|
788 | vec=linspace(0,1,255);%define a linear greyscale colormap
|
---|
789 | map=[vec' vec' vec'];
|
---|
790 | colormap(map); %grey scale color map
|
---|
791 | else
|
---|
792 | colormap('default'); % standard faulse colors for div, vort , scalar fields
|
---|
793 | end
|
---|
794 | end
|
---|
795 |
|
---|
796 | % case of color images
|
---|
797 | else
|
---|
798 | if BW
|
---|
799 | B=uint16(sum(A,3));
|
---|
800 | else
|
---|
801 | B=uint8(A);
|
---|
802 | end
|
---|
803 | MinA=0;
|
---|
804 | MaxA=255;
|
---|
805 | end
|
---|
806 |
|
---|
807 | % display usual image
|
---|
808 | if ~CheckContour
|
---|
809 | % interpolate field to increase resolution of image display
|
---|
810 | test_interp=1;
|
---|
811 | if max(np) <= 64
|
---|
812 | npxy=8*np;% increase the resolution 8 times
|
---|
813 | elseif max(np) <= 128
|
---|
814 | npxy=4*np;% increase the resolution 4 times
|
---|
815 | elseif max(np) <= 256
|
---|
816 | npxy=2*np;% increase the resolution 2 times
|
---|
817 | else
|
---|
818 | npxy=np;
|
---|
819 | test_interp=0; % no interpolation done
|
---|
820 | end
|
---|
821 | if test_interp==1%if we interpolate
|
---|
822 | x=linspace(AX(1),AX(2),np(2));
|
---|
823 | y=linspace(AY(1),AY(2),np(1));
|
---|
824 | [X,Y]=meshgrid(x,y);
|
---|
825 | xi=linspace(AX(1),AX(2),npxy(2));
|
---|
826 | yi=linspace(AY(1),AY(2),npxy(1));
|
---|
827 | B = interp2(X,Y,double(B),xi,yi');
|
---|
828 | end
|
---|
829 | % create new image if there no image handle is found
|
---|
830 | if isempty(hima)
|
---|
831 | tag=get(haxes,'Tag');
|
---|
832 | if MinA<MaxA
|
---|
833 | hima=imagesc(AX,AY,B,[MinA MaxA]);
|
---|
834 | else % to deal with uniform field
|
---|
835 | hima=imagesc(AX,AY,B,[MaxA-1 MaxA]);
|
---|
836 | end
|
---|
837 | set(hima,'Tag','ima','HitTest','off')
|
---|
838 | set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
|
---|
839 | uistack(hima, 'bottom')
|
---|
840 | % update an existing image
|
---|
841 | else
|
---|
842 | set(hima,'CData',B);
|
---|
843 | if MinA<MaxA
|
---|
844 | set(haxes,'CLim',[MinA MaxA])
|
---|
845 | else
|
---|
846 | set(haxes,'CLim',[MinA MaxA+1])
|
---|
847 | end
|
---|
848 | set(hima,'XData',AX);
|
---|
849 | set(hima,'YData',AY);
|
---|
850 | end
|
---|
851 | end
|
---|
852 | test_ima=1;
|
---|
853 |
|
---|
854 | %display the colorbar code for B/W images if Poscolorbar not empty
|
---|
855 | if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar)
|
---|
856 | if isempty(hcol)||~ishandle(hcol)
|
---|
857 | hcol=colorbar;%create new colorbar
|
---|
858 | end
|
---|
859 | if length(PosColorbar)==4
|
---|
860 | set(hcol,'Position',PosColorbar)
|
---|
861 | end
|
---|
862 | %YTick=0;%default
|
---|
863 | if MaxA>MinA
|
---|
864 | if CheckContour
|
---|
865 | colbarlim=get(hcol,'YLim');
|
---|
866 | scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
|
---|
867 | YTick=cont_pos(2:end-1);
|
---|
868 | YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
|
---|
869 | set(hcol,'YTick',YTick_scaled);
|
---|
870 | elseif (isfield(PlotParam.Scalar,'CheckBW') && isequal(PlotParam.Scalar.CheckBW,1))||isa(A,'uint8')|| isa(A,'uint16')%images
|
---|
871 | hi=get(hcol,'children');
|
---|
872 | if iscell(hi)%multiple images in colorbar
|
---|
873 | hi=hi{1};
|
---|
874 | end
|
---|
875 | set(hi,'YData',[MinA MaxA])
|
---|
876 | set(hi,'CData',(1:256)')
|
---|
877 | set(hcol,'YLim',[MinA MaxA])
|
---|
878 | YTick=colbartick(MinA,MaxA);
|
---|
879 | set(hcol,'YTick',YTick)
|
---|
880 | else
|
---|
881 | hi=get(hcol,'children');
|
---|
882 | if iscell(hi)%multiple images in colorbar
|
---|
883 | hi=hi{1};
|
---|
884 | end
|
---|
885 | set(hi,'YData',[MinA MaxA])
|
---|
886 | set(hi,'CData',(1:64)')
|
---|
887 | YTick=colbartick(MinA,MaxA);
|
---|
888 | set(hcol,'YLim',[MinA MaxA])
|
---|
889 | set(hcol,'YTick',YTick)
|
---|
890 | end
|
---|
891 | set(hcol,'Yticklabel',num2str(YTick'));
|
---|
892 | end
|
---|
893 | elseif ishandle(hcol)
|
---|
894 | delete(hcol); %erase existing colorbar if not needed
|
---|
895 | end
|
---|
896 | else%no scalar plot
|
---|
897 | if ~isempty(hima) && ishandle(hima)
|
---|
898 | delete(hima)
|
---|
899 | end
|
---|
900 | if ~isempty(hcol)&& ishandle(hcol)
|
---|
901 | delete(hcol)
|
---|
902 | end
|
---|
903 | PlotParamOut=rmfield(PlotParamOut,'Scalar');
|
---|
904 | end
|
---|
905 |
|
---|
906 | %% vector plot %%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
907 | if test_vec
|
---|
908 | %vector scale representation
|
---|
909 | if size(vec_U,1)==numel(vec_Y) && size(vec_U,2)==numel(vec_X); % x, y coordinate variables
|
---|
910 | [vec_X,vec_Y]=meshgrid(vec_X,vec_Y);
|
---|
911 | end
|
---|
912 | vec_X=reshape(vec_X,1,numel(vec_X));%reshape in matlab vectors
|
---|
913 | vec_Y=reshape(vec_Y,1,numel(vec_Y));
|
---|
914 | vec_U=reshape(vec_U,1,numel(vec_U));
|
---|
915 | vec_V=reshape(vec_V,1,numel(vec_V));
|
---|
916 | MinMaxX=max(vec_X)-min(vec_X);
|
---|
917 | if isfield(PlotParam.Vectors,'CheckFixVectors') && isequal(PlotParam.Vectors.CheckFixVectors,1)&& isfield(PlotParam.Vectors,'VecScale')...
|
---|
918 | &&~isempty(PlotParam.Vectors.VecScale) && isa(PlotParam.Vectors.VecScale,'double') %fixed vector scale
|
---|
919 | scale=PlotParam.Vectors.VecScale; %impose the length of vector representation
|
---|
920 | else
|
---|
921 | if ~test_false %remove false vectors
|
---|
922 | indsel=1:numel(vec_X);%
|
---|
923 | end
|
---|
924 | if isempty(vec_U)
|
---|
925 | scale=1;
|
---|
926 | else
|
---|
927 | if isempty(indsel)
|
---|
928 | MaxU=max(abs(vec_U));
|
---|
929 | MaxV=max(abs(vec_V));
|
---|
930 | else
|
---|
931 | MaxU=max(abs(vec_U(indsel)));
|
---|
932 | MaxV=max(abs(vec_V(indsel)));
|
---|
933 | end
|
---|
934 | scale=MinMaxX/(max(MaxU,MaxV)*50);
|
---|
935 | PlotParam.Vectors.VecScale=scale;%update the 'scale' display
|
---|
936 | end
|
---|
937 | end
|
---|
938 |
|
---|
939 | %record vectors on the plotting axes
|
---|
940 | if test_C==0
|
---|
941 | vec_C=ones(1,numel(vec_X));
|
---|
942 | end
|
---|
943 |
|
---|
944 | %decimate by a factor 2 in vector mesh(4 in nbre of vectors)
|
---|
945 | if isfield(PlotParam.Vectors,'CheckDecimate4') && PlotParam.Vectors.CheckDecimate4
|
---|
946 | diffy=diff(vec_Y); %difference dy=vec_Y(i+1)-vec_Y(i)
|
---|
947 | dy_thresh=max(abs(diffy))/2;
|
---|
948 | ind_jump=find(abs(diffy) > dy_thresh); %indices with diff(vec_Y)> max/2, detect change of line
|
---|
949 | ind_sel=1:ind_jump(1);%select the first line
|
---|
950 | for i=2:2:length(ind_jump)-1
|
---|
951 | ind_sel=[ind_sel (ind_jump(i)+1:ind_jump(i+1))];% select the odd lines
|
---|
952 | end
|
---|
953 | nb_sel=length(ind_sel);
|
---|
954 | ind_sel=ind_sel(1:2:nb_sel);% take half the points on a line
|
---|
955 | vec_X=vec_X(ind_sel);
|
---|
956 | vec_Y=vec_Y(ind_sel);
|
---|
957 | vec_U=vec_U(ind_sel);
|
---|
958 | vec_V=vec_V(ind_sel);
|
---|
959 | vec_C=vec_C(ind_sel);
|
---|
960 | if ~isempty(ivar_F)
|
---|
961 | vec_F=vec_F(ind_sel);
|
---|
962 | end
|
---|
963 | if ~isempty(ivar_FF)
|
---|
964 | vec_FF=vec_FF(ind_sel);
|
---|
965 | end
|
---|
966 | end
|
---|
967 |
|
---|
968 | %get main level color code
|
---|
969 | [colorlist,col_vec,PlotParamOut.Vectors]=set_col_vec(PlotParam.Vectors,vec_C);
|
---|
970 |
|
---|
971 | % take flags into account: add flag colors to the list of colors
|
---|
972 | sizlist=size(colorlist);
|
---|
973 | nbcolor=sizlist(1);
|
---|
974 | if test_black
|
---|
975 | nbcolor=nbcolor+1;
|
---|
976 | colorlist(nbcolor,:)=[0 0 0]; %add black to the list of colors
|
---|
977 | if ~isempty(ivar_FF)
|
---|
978 | % ind_flag=find(vec_F~=1 & vec_F~=0 & vec_FF==0); %flag warning but not false
|
---|
979 | col_vec(vec_F~=1 & vec_F~=0 & vec_FF==0)=nbcolor;
|
---|
980 | else
|
---|
981 | col_vec(vec_F~=1 & vec_F~=0)=nbcolor;
|
---|
982 | end
|
---|
983 | end
|
---|
984 | nbcolor=nbcolor+1;
|
---|
985 | if ~isempty(ivar_FF)
|
---|
986 | if isfield(PlotParam.Vectors,'CheckHideFalse') && PlotParam.Vectors.CheckHideFalse==1
|
---|
987 | colorlist(nbcolor,:)=[NaN NaN NaN];% no plot of false vectors
|
---|
988 | else
|
---|
989 | colorlist(nbcolor,:)=[1 0 1];% magenta color
|
---|
990 | end
|
---|
991 | col_vec(vec_FF~=0)=nbcolor;
|
---|
992 | end
|
---|
993 | %plot vectors:
|
---|
994 | quiresetn(haxes,vec_X,vec_Y,vec_U,vec_V,scale,colorlist,col_vec);
|
---|
995 |
|
---|
996 | else
|
---|
997 | hvec=findobj(haxes,'Tag','vel');
|
---|
998 | if ~isempty(hvec)
|
---|
999 | delete(hvec);
|
---|
1000 | end
|
---|
1001 | PlotParamOut=rmfield(PlotParamOut,'Vectors');
|
---|
1002 | end
|
---|
1003 |
|
---|
1004 | %listfields={'AY','AX','A','X','Y','U','V','C','W','F','FF'};
|
---|
1005 | %listdim={'AY','AX',{'AY','AX'},'nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors','nb_vectors'};
|
---|
1006 | %Role={'coord_y','coord_x','scalar','coord_x','coord_y','vector_x','vector_y','scalar','vector_z','warnflag','errorflag'};
|
---|
1007 | %ind_select=[];
|
---|
1008 | nbvar=0;
|
---|
1009 |
|
---|
1010 | %store the coordinate extrema occupied by the field
|
---|
1011 | if ~isempty(Data)
|
---|
1012 | XMin=[];
|
---|
1013 | XMax=[];
|
---|
1014 | YMin=[];
|
---|
1015 | YMax=[];
|
---|
1016 | fix_lim=isfield(PlotParam,'CheckFixLimits') && PlotParam.CheckFixLimits;
|
---|
1017 | if fix_lim
|
---|
1018 | if ~isfield(PlotParam,'MinX')||~isfield(PlotParam,'MaxX')||~isfield(PlotParam,'MinY')||~isfield(PlotParam,'MaxY')
|
---|
1019 | fix_lim=0; %free limits if limits are not set,
|
---|
1020 | else
|
---|
1021 | XMin=PlotParam.MinX
|
---|
1022 | XMax=PlotParam.MaxX;
|
---|
1023 | YMin=PlotParam.MinY;
|
---|
1024 | YMax=PlotParam.MaxY;
|
---|
1025 | end %else PlotParamOut.XMin =PlotParam.XMin...
|
---|
1026 | else
|
---|
1027 | if test_ima %both background image and vectors coexist, take the wider bound
|
---|
1028 | XMin=min(AX);
|
---|
1029 | XMax=max(AX);
|
---|
1030 | YMin=min(AY);
|
---|
1031 | YMax=max(AY);
|
---|
1032 | if test_vec
|
---|
1033 | XMin=min(XMin,min(vec_X));
|
---|
1034 | XMax=max(XMax,max(vec_X));
|
---|
1035 | YMin=min(YMin,min(vec_Y));
|
---|
1036 | YMax=max(YMax,max(vec_Y));
|
---|
1037 | end
|
---|
1038 | elseif test_vec
|
---|
1039 | XMin=min(vec_X);
|
---|
1040 | XMax=max(vec_X);
|
---|
1041 | YMin=min(vec_Y);
|
---|
1042 | YMax=max(vec_Y);
|
---|
1043 | end
|
---|
1044 | end
|
---|
1045 | % PlotParamOut.RangeX=[XMin XMax]; %range of x, to be stored in the user data of the plot axes
|
---|
1046 | % PlotParamOut.RangeY=[YMin YMax]; %range of x, to be stored in the user data of the plot axes
|
---|
1047 | % if ~fix_lim
|
---|
1048 | PlotParamOut.MinX=XMin;
|
---|
1049 | PlotParamOut.MaxX=XMax;
|
---|
1050 | PlotParamOut.MinY=YMin;
|
---|
1051 | PlotParamOut.MaxY=YMax;
|
---|
1052 | if XMax>XMin
|
---|
1053 | set(haxes,'XLim',[XMin XMax]);% set x limits of frame in axes coordinates
|
---|
1054 | end
|
---|
1055 | if YMax>YMin
|
---|
1056 | set(haxes,'YLim',[YMin YMax]);% set x limits of frame in axes coordinates
|
---|
1057 | end
|
---|
1058 | % end
|
---|
1059 | set(haxes,'YDir','normal')
|
---|
1060 | set(get(haxes,'XLabel'),'String',[XName ' (' x_units ')']);
|
---|
1061 | set(get(haxes,'YLabel'),'String',[YName ' (' y_units ')']);
|
---|
1062 | PlotParamOut.x_units=x_units;
|
---|
1063 | PlotParamOut.y_units=y_units;
|
---|
1064 | end
|
---|
1065 | %-------------------------------------------------------------------
|
---|
1066 | % --- function for plotting vectors
|
---|
1067 | %INPUT:
|
---|
1068 | % haxes: handles of the plotting axes
|
---|
1069 | % x,y,u,v: vectors coordinates and vector components to plot, arrays withb the same dimension
|
---|
1070 | % scale: scaling factor for vector length representation
|
---|
1071 | % colorlist(icolor,:): list of vector colors, dim (nbcolor,3), depending on color #i
|
---|
1072 | % col_vec: matlab vector setting the color number #i for each velocity vector
|
---|
1073 | function quiresetn(haxes,x,y,u,v,scale,colorlist,col_vec)
|
---|
1074 | %-------------------------------------------------------------------
|
---|
1075 | %define arrows
|
---|
1076 | theta=0.5 ;%angle arrow
|
---|
1077 | alpha=0.3 ;%length arrow
|
---|
1078 | rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
|
---|
1079 | %find the existing lines
|
---|
1080 | h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
|
---|
1081 | sizh=size(h);
|
---|
1082 | set(h,'EraseMode','xor');
|
---|
1083 | set(haxes,'NextPlot','replacechildren');
|
---|
1084 |
|
---|
1085 | %drawnow
|
---|
1086 | %create lines (if no lines) or modify them
|
---|
1087 | if ~isequal(size(col_vec),size(x))
|
---|
1088 | col_vec=ones(size(x));% case of error in col_vec input
|
---|
1089 | end
|
---|
1090 | sizlist=size(colorlist);
|
---|
1091 | ncolor=sizlist(1);
|
---|
1092 |
|
---|
1093 | for icolor=1:ncolor
|
---|
1094 | %determine the line positions for each color icolor
|
---|
1095 | ind=find(col_vec==icolor);
|
---|
1096 | xc=x(ind);
|
---|
1097 | yc=y(ind);
|
---|
1098 | uc=u(ind)*scale;
|
---|
1099 | vc=v(ind)*scale;
|
---|
1100 | n=size(xc);
|
---|
1101 | xN=NaN*ones(size(xc));
|
---|
1102 | matx=[xc(:)-uc(:)/2 xc(:)+uc(:)/2 xN(:)]';
|
---|
1103 | % matx=[xc(:) xc(:)+uc(:) xN(:)]';
|
---|
1104 | matx=reshape(matx,1,3*n(2));
|
---|
1105 | maty=[yc(:)-vc(:)/2 yc(:)+vc(:)/2 xN(:)]';
|
---|
1106 | % maty=[yc(:) yc(:)+vc(:) xN(:)]';
|
---|
1107 | maty=reshape(maty,1,3*n(2));
|
---|
1108 |
|
---|
1109 | %determine arrow heads
|
---|
1110 | arrowplus=rot*[uc;vc];
|
---|
1111 | arrowmoins=rot'*[uc;vc];
|
---|
1112 | x1=xc+uc/2-arrowplus(1,:);
|
---|
1113 | x2=xc+uc/2;
|
---|
1114 | x3=xc+uc/2-arrowmoins(1,:);
|
---|
1115 | y1=yc+vc/2-arrowplus(2,:);
|
---|
1116 | y2=yc+vc/2;
|
---|
1117 | y3=yc+vc/2-arrowmoins(2,:);
|
---|
1118 | matxar=[x1(:) x2(:) x3(:) xN(:)]';
|
---|
1119 | matxar=reshape(matxar,1,4*n(2));
|
---|
1120 | matyar=[y1(:) y2(:) y3(:) xN(:)]';
|
---|
1121 | matyar=reshape(matyar,1,4*n(2));
|
---|
1122 | %draw the line or modify the existing ones
|
---|
1123 | tri=reshape(1:3*length(uc),3,[])';
|
---|
1124 | isn=isnan(colorlist(icolor,:));%test if color NaN
|
---|
1125 | if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
|
---|
1126 | if ~isn(1) %if the vectors are visible color not nan
|
---|
1127 | if n(2)>0
|
---|
1128 | hold on
|
---|
1129 | line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
|
---|
1130 | line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
|
---|
1131 | end
|
---|
1132 | end
|
---|
1133 | else
|
---|
1134 | if isn(1)
|
---|
1135 | delete(h(2*icolor-1))
|
---|
1136 | delete(h(2*icolor))
|
---|
1137 | else
|
---|
1138 | set(h(2*icolor-1),'Xdata',matx,'Ydata',maty);
|
---|
1139 | set(h(2*icolor-1),'Color',colorlist(icolor,:));
|
---|
1140 | set(h(2*icolor-1),'EraseMode','xor');
|
---|
1141 | set(h(2*icolor),'Xdata',matxar,'Ydata',matyar);
|
---|
1142 | set(h(2*icolor),'Color',colorlist(icolor,:));
|
---|
1143 | set(h(2*icolor),'EraseMode','xor');
|
---|
1144 | end
|
---|
1145 | end
|
---|
1146 | end
|
---|
1147 | if sizh(1) > 2*ncolor
|
---|
1148 | for icolor=ncolor+1 : sizh(1)/2%delete additional objects
|
---|
1149 | delete(h(2*icolor-1))
|
---|
1150 | delete(h(2*icolor))
|
---|
1151 | end
|
---|
1152 | end
|
---|
1153 |
|
---|
1154 | %-------------------------------------------------------------------
|
---|
1155 | % ---- determine tick positions for colorbar
|
---|
1156 | function YTick=colbartick(MinA,MaxA)
|
---|
1157 | %-------------------------------------------------------------------
|
---|
1158 | %determine tick positions with "simple" values between MinA and MaxA
|
---|
1159 | YTick=0;%default
|
---|
1160 | maxabs=max([abs(MinA) abs(MaxA)]);
|
---|
1161 | if maxabs>0
|
---|
1162 | ord=10^(floor(log10(maxabs)));%order of magnitude
|
---|
1163 | div=1;
|
---|
1164 | siz2=1;
|
---|
1165 | while siz2<2
|
---|
1166 | % values=[-9:div:9];
|
---|
1167 | values=-10:div:10;
|
---|
1168 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);%indices of 'values' such that MinA<ord*values<MaxA
|
---|
1169 | siz=size(ind);
|
---|
1170 | if siz(2)<4%if there are less than 4 selected values (4 levels)
|
---|
1171 | values=-9:0.5*div:9;
|
---|
1172 | ind=find((ord*values-MaxA)<0 & (ord*values-MinA)>0);
|
---|
1173 | end
|
---|
1174 | siz2=size(ind,2);
|
---|
1175 | % siz2=siz(2)
|
---|
1176 | div=div/10;
|
---|
1177 | end
|
---|
1178 | YTick=ord*values(ind);
|
---|
1179 | end
|
---|
1180 |
|
---|