Changeset 292 for trunk/src/plot_field.m
- Timestamp:
- Nov 21, 2011, 11:12:06 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r252 r292 4 4 % This function is used by uvmat to plot fields. It automatically chooses the representation 5 5 % appropriate to the input field structure: 6 % 2D vector fields are represented by arrows, 2D scalar fie dlds by grey scale images or contour plots, 1D fields are represented by usual plot with (abscissa, ordinate).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 7 % The input field structure is first tested by check_field_structure.m, 8 8 % then split into blocks of related variables by find_field_indices.m. 9 % The dimensionality of each block is obtained by this fu ction9 % The dimensionality of each block is obtained by this function 10 10 % considering the presence of variables with the attribute .Role='coord_x' 11 11 % and/or coord_y and/or coord_z (case of unstructured coordinates), or … … 52 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 53 % 54 % PlotParam: parameters for plotting, as read on the uvmat interface (by function 'read_plot_param.m')55 % . FixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits56 % . FixEqual: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.54 % PlotParam: parameters for plotting, as read on the uvmat or view_field interface (by function 'read_GUI.m') 55 % .Coordinates.CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits 56 % .Coordinates.CheckFixEqual: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales. 57 57 % --scalars-- 58 58 % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default 59 59 % .Scalar.MinA: lower bound (saturation) for the scalar representation, min(field) by default 60 % .Scalar. FixScal: =0 (default) lower and upper bounds of the scalar representation set to the min and max of the field60 % .Scalar.CheckFixScal: =0 (default) lower and upper bounds of the scalar representation set to the min and max of the field 61 61 % =1 lower and upper bound imposed by .AMax and .MinA 62 % .Scalar. BW= 1 black and white representation imposed, =0 by default.63 % .Scalar.C ontours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default62 % .Scalar.CheckBW= 1 black and white representation imposed, =0 by default. 63 % .Scalar.CheckContours= 1: represent scalars by contour plots (Matlab function 'contour'); =0 by default 64 64 % .IncrA : contour interval 65 65 % -- vectors-- 66 66 % .Vectors.VecScale: scale for the vector representation 67 % .Vectors. FixVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale68 % .Vectors. HideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented;69 % .Vectors. HideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation;70 % .Vectors. decimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate67 % .Vectors.CheckFixVec: =0 (default) automatic length for vector representation, =1: length set by .VecScale 68 % .Vectors.CheckHideFalse= 0 (default) false vectors represented in magenta, =1: false vectors not represented; 69 % .Vectors.CheckHideWarning= 0 (default) vectors marked by warnflag~=0 marked in black, 1: no warning representation; 70 % .Vectors.CheckDecimate4 = 0 (default) all vectors reprtesented, =1: half of the vectors represented along each coordinate 71 71 % -- vector color-- 72 72 % .Vectors.ColorCode= 'black','white': imposed color (default ='blue') … … 77 77 % .Vectors.colcode1 : first threshold for rgb, first value for'continuous' 78 78 % .Vectors.colcode2 : second threshold for rgb, last value (saturation) for 'continuous' 79 % .Vectors. FixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC79 % .Vectors.CheckFixedCbounds; =0 (default): the bounds on C representation are min and max, =1: they are fixed by .Minc and .MaxC 80 80 % .Vectors.MinC = imposed minimum of the scalar field used for vector color; 81 81 % .Vectors.MaxC = imposed maximum of the scalar field used for vector color; 82 82 % 83 %84 83 % PosColorbar: if not empty, display a colorbar for B&W images 85 84 % imposed position of the colorbar (ex [0.821 0.471 0.019 0.445]) … … 102 101 103 102 function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar) 104 % TODO:105 103 % use htext: handles of the text edit box (uicontrol) 106 104 % introduce PlotParam.Hold: 'on' or 'off' (for curves) … … 111 109 PlotType='text'; %default 112 110 PlotParamOut=PlotParam;%default 111 Coordinates=[]; 112 if isfield(PlotParam,'Coordinates') 113 Coordinates=PlotParam.Coordinates; 114 end 113 115 114 116 %% test axes and figure … … 175 177 176 178 %% set axes properties 177 if isfield( PlotParam,'FixLimits') && isequal(PlotParam.FixLimits,1) %adjust the graph limits*179 if isfield(Coordinates,'CheckFixLimits') && isequal(Coordinates.CheckFixLimits,1) %adjust the graph limits* 178 180 set(haxes,'XLimMode', 'manual') 179 181 set(haxes,'YLimMode', 'manual') … … 182 184 set(haxes,'YLimMode', 'auto') 183 185 end 184 if ~isfield( PlotParam,'FixEqual')&& isfield(Data,'CoordUnit')185 PlotParam.FixEqual=1;186 end 187 if isfield( PlotParam,'FixEqual') && isequal(PlotParam.FixEqual,1)186 if ~isfield(Coordinates,'CheckFixEqual')&& isfield(Data,'CoordUnit') 187 Coordinates.CheckFixEqual=1; 188 end 189 if isfield(Coordinates,'CheckFixEqual') && isequal(Coordinates.CheckFixEqual,1) 188 190 set(haxes,'DataAspectRatioMode','manual') 189 191 set(haxes,'DataAspectRatio',[1 1 1]) … … 222 224 plot_profile([],[],[],haxes);% 223 225 else 224 PlotParamOut=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam);%226 Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);% 225 227 if testzoomaxes 226 [zoomaxes, PlotParamOut]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam);228 [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates); 227 229 AxeData.ZoomAxes=zoomaxes; 230 end 231 if ~isempty(Coordinates) 232 PlotParamOut.Coordinates=Coordinates; 228 233 end 229 234 PlotType='line'; … … 242 247 end 243 248 if isfield(PlotParamOut,'MinX') 244 % 'TESTplot'245 % haxes246 % PlotParamOut.MinX247 % PlotParamOut.MaxY248 % set(haxes,'XLim',[PlotParamOut.MinX PlotParamOut.MaxX])249 % set(haxes,'YLim',[PlotParamOut.MinY PlotParamOut.MaxY])250 249 AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX]; 251 250 AxeData.RangeY=[PlotParamOut.MinY PlotParamOut.MaxY];%[PlotParamOut.MinY PlotParamOut.MaxY] … … 262 261 set(hfig,'UserData',FigData) 263 262 end 264 263 265 264 %------------------------------------------------------------------- 266 265 function errormsg=plot_text(FieldData,CellVarIndex,htext) 267 266 %------------------------------------------------------------------- 268 % if exist('hdisplay_in','var') && ~isempty(hdisplay_in) && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol')269 % hdisplay=hdisplay_in;270 % else271 % figure;%create new figure272 % hdisplay=uicontrol('Style','edit', 'Units','normalized','Position', [0 0 1 1],'Max',2,'FontName','monospaced');273 % end274 267 errormsg=[]; 275 268 txt_cell={}; 276 269 for icell=1:length(CellVarIndex) 277 270 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName 278 % ff=fields(FieldData);%list of field names279 % vv=struct2cell(FieldData);%list of field values280 %281 % for icell=1:length(vv)282 271 for ivar=1:length(VarIndex) 283 272 VarName=FieldData.ListVarName{VarIndex(ivar)}; 284 eval(['VarValue=FieldData.' VarName ';'])273 VarValue=FieldData.(VarName); 285 274 if size(VarValue,1)~=1 286 275 VarValue=VarValue'; … … 290 279 end 291 280 end 292 293 281 set(htext,'String',txt_cell) 294 % txt_cell=[txt_cell {num2str( 295 % Tabcell{icell,1}=ff{icell}; 296 % ss=vv{icell}; 297 % sizss=size(ss); 298 % if isnumeric(ss) 299 % if sizss(1)<=1 && length(ss)<5 300 % displ{icell}=num2str(ss); 301 % else 302 % displ{icell}=[class(ss) ', size ' num2str(size(ss))]; 303 % end 304 % elseif ischar(ss) 305 % displ{icell}=ss; 306 % elseif iscell(ss) 307 % sizcell=size(ss); 308 % if sizcell(1)==1 && length(sizcell)==2 %line cell 309 % ssline='{'''; 310 % for icolumn=1:sizcell(2) 311 % if isnumeric(ss{icolumn}) 312 % if size(ss{icolumn},1)<=1 && length(ss{icolumn})<5 313 % sscolumn=num2str(ss{icolumn});%line vector 314 % else 315 % sscolumn=[class(ss{icolumn}) ', size ' num2str(size(ss{icolumn}))]; 316 % end 317 % elseif ischar(ss{icolumn}) 318 % sscolumn=ss{icolumn}; 319 % else 320 % sscolumn=class(ss{icolumn}); 321 % end 322 % if icolumn==1 323 % ssline=[ssline sscolumn]; 324 % else 325 % ssline=[ssline ''',''' sscolumn]; 326 % end 327 % end 328 % displ{icell}=[ssline '''}']; 329 % else 330 % displ{icell}=[class(ss) ', size ' num2str(sizcell)]; 331 % end 332 % else 333 % displ{icell}=class(ss); 334 % end 335 % Tabcell{icell,2}=displ{icell}; 336 % end 337 % Tabchar=cell2tab(Tabcell,': '); 338 % set(hdisplay,'String', Tabchar) 339 282 set(htext,'UserData',txt_cell)% for storage during mouse display 340 283 341 284 %------------------------------------------------------------------- 342 function PlotParamOut=plot_profile(data,CellVarIndex,VarType,haxes,PlotParam)285 function CoordinatesOut=plot_profile(data,CellVarIndex,VarType,haxes,Coordinates) 343 286 %------------------------------------------------------------------- 344 287 345 if ~exist(' PlotParam','var')346 PlotParam=[];347 end 348 PlotParamOut=PlotParam; %default288 if ~exist('Coordinates','var') 289 Coordinates=[]; 290 end 291 CoordinatesOut=Coordinates; %default 349 292 hfig=get(haxes,'parent'); 350 293 %suppress existing plot isf empty data … … 361 304 end 362 305 363 364 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]; 365 307 set(haxes,'ColorOrder',ColorOrder) 366 if isfield( PlotParam,'NextPlot')367 set(haxes,'NextPlot', PlotParam.NextPlot)308 if isfield(Coordinates,'NextPlot') 309 set(haxes,'NextPlot',Coordinates.NextPlot) 368 310 end 369 311 % adjust the size of the plot to include the whole field, … … 372 314 373 315 %% prepare the string for plot command 374 %initiate the plot command375 316 plotstr='hhh=plot('; 376 % textmean={};377 317 coord_x_index=[]; 378 318 xtitle=''; … … 513 453 514 454 %% determine axes bounds 515 PlotParamOut.RangeX=[min(XMin) max(XMax)];516 PlotParamOut.RangeY=[min(YMin_cell) max(YMax_cell)];517 fix_lim=isfield( PlotParam,'FixLimits') && PlotParam.FixLimits;455 CoordinatesOut.RangeX=[min(XMin) max(XMax)]; 456 CoordinatesOut.RangeY=[min(YMin_cell) max(YMax_cell)]; 457 fix_lim=isfield(Coordinates,'FixLimits') && Coordinates.FixLimits; 518 458 if fix_lim 519 if ~isfield( PlotParam,'MinX')||~isfield(PlotParam,'MaxX')||~isfield(PlotParam,'MinY')||~isfield(PlotParam,'MaxY')459 if ~isfield(Coordinates,'MinX')||~isfield(Coordinates,'MaxX')||~isfield(Coordinates,'MinY')||~isfield(Coordinates,'MaxY') 520 460 fix_lim=0; %free limits if lits are not set, 521 461 end 522 462 end 523 463 if ~fix_lim 524 PlotParamOut.MinX=min(XMin);525 PlotParamOut.MaxX=max(XMax);526 PlotParamOut.MinY=min(YMin_cell);527 PlotParamOut.MaxY=max(YMax_cell);464 CoordinatesOut.MinX=min(XMin); 465 CoordinatesOut.MaxX=max(XMax); 466 CoordinatesOut.MinY=min(YMin_cell); 467 CoordinatesOut.MaxY=max(YMax_cell); 528 468 end 529 469 … … 719 659 %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%% 720 660 721 if ~isfield(PlotParam.Scalar,'C ontours')661 if ~isfield(PlotParam.Scalar,'CheckContours') 722 662 PlotParam.Scalar.Contours=0; %default 723 663 end
Note: See TracChangeset
for help on using the changeset viewer.