Changeset 429 for trunk/src/plot_field.m
- Timestamp:
- May 22, 2012, 1:07:40 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r428 r429 48 48 % .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits 49 49 % .Coordinates.CheckFixAspectRatio: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales. 50 % .Coordinates.AspectRatio: imposed aspect ratio y/x of axis unit plots 50 51 % --scalars-- 51 52 % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default … … 143 144 end 144 145 145 %% pure text display 146 if isempty(index_2D) && isempty(index_1D)% no plot 147 hfig=findobj(allchild(0),'Tag','fig_text_display'); 148 if isempty(hfig) 149 hfig=figure('name','text_display','Tag','fig_text_display'); 150 end 146 %% test axes and figure 147 testnewfig=1;%test to create a new figure (default) 148 testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes 149 if exist('haxes','var') 150 if ishandle(haxes) 151 if isequal(get(haxes,'Type'),'axes') 152 testnewfig=0; 153 AxeData=get(haxes,'UserData'); 154 if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes) 155 if isequal(get(AxeData.ZoomAxes,'Type'),'axes') 156 testzoomaxes=1; 157 zoomaxes=AxeData.ZoomAxes; 158 end 159 end 160 end 161 end 162 end 163 164 %% create a new figure and axes if the plotting axes does not exist 165 if testnewfig 166 hfig=figure; 167 set(hfig,'Units','normalized') 168 haxes=axes; 169 set(haxes,'position',[0.13,0.2,0.775,0.73]) 170 PlotParam.NextPlot='add'; %parameter for plot_profile and plot_his 171 else 172 hfig=get(haxes,'parent'); 173 set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure 174 set(hfig,'CurrentAxes',haxes)% haxes becomes the current axes of the parent figure 175 end 176 177 %% set axes properties 178 if isfield(PlotParam.Coordinates,'CheckFixLimits') && isequal(PlotParam.Coordinates.CheckFixLimits,1) %adjust the graph limits 179 set(haxes,'XLimMode', 'manual') 180 set(haxes,'YLimMode', 'manual') 181 else 182 set(haxes,'XLimMode', 'auto') 183 set(haxes,'YLimMode', 'auto') 184 end 185 % if ~isfield(PlotParam.Coordinates,'CheckFixAspectRatio')&& isfield(Data,'CoordUnit') 186 % PlotParam.Coordinates.CheckFixAspectRatio=1;% if CoordUnit is defined, the two coordiantes should be plotted with equal scale by default 187 % end 188 errormsg=''; 189 PlotParamOut.Coordinates=[]; %default output 190 AxeData=get(haxes,'UserData'); 191 192 %% 2D plots 193 if isempty(index_2D) 194 plot_plane([],[],[],haxes);%removes images or vector plots in the absence of 2D field plot 195 else %plot 2D field 196 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar); 197 AxeData.NbDim=2; 198 if testzoomaxes && isempty(errormsg) 199 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar); 200 AxeData.ZoomAxes=zoomaxes; 201 end 202 end 203 204 %% 1D plot (usual graph y vs x) 205 if isempty(index_1D) 206 if ~isempty(haxes) 207 plot_profile([],[],[],haxes);%removes usual praphs y vs x in the absence of 1D field plot 208 end 209 else %plot 1D field (usual graph y vs x) 210 Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);% 211 if testzoomaxes 212 [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates); 213 AxeData.ZoomAxes=zoomaxes; 214 end 215 if ~isempty(Coordinates) 216 PlotParamOut.Coordinates=Coordinates; 217 end 218 PlotType='line'; 219 end 220 221 %% text display 222 if isempty(index_2D) && isempty(index_1D)%text display alone 223 htext=findobj(hfig,'Tag','TableDisplay'); 224 else %text display added to plot 151 225 htext=findobj(hfig,'Tag','text_display'); 152 if isempty(htext) 153 htext=uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71],'Tag','text_display'); 154 end 226 end 227 if ~isempty(htext) 155 228 if isempty(index_0D) 156 229 set(htext,'String',{''}) … … 158 231 [errormsg]=plot_text(Data,CellVarIndex(index_0D),VarType(index_0D),htext); 159 232 end 160 haxes=[];161 end162 163 %% test axes and figure164 if ~isempty(index_2D)|| ~isempty(index_1D)% plot165 testnewfig=1;%test to create a new figure (default)166 testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes167 if exist('haxes','var')168 if ishandle(haxes)169 if isequal(get(haxes,'Type'),'axes')170 testnewfig=0;171 AxeData=get(haxes,'UserData');172 if isfield(AxeData,'ZoomAxes')&& ishandle(AxeData.ZoomAxes)173 if isequal(get(AxeData.ZoomAxes,'Type'),'axes')174 testzoomaxes=1;175 zoomaxes=AxeData.ZoomAxes;176 end177 end178 end179 end180 end181 % create a new figure and axes if the plotting axes does not exist182 if testnewfig183 hfig=figure;184 set(hfig,'Units','normalized')185 haxes=axes;186 set(haxes,'position',[0.13,0.2,0.775,0.73])187 PlotParam.NextPlot='add'; %parameter for plot_profile and plot_his188 else189 hfig=get(haxes,'parent');190 set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure191 set(hfig,'CurrentAxes',haxes)% haxes becomes the current axes of the parent figure192 end193 194 %% set axes properties195 if isfield(PlotParam.Coordinates,'CheckFixLimits') && isequal(PlotParam.Coordinates.CheckFixLimits,1) %adjust the graph limits196 set(haxes,'XLimMode', 'manual')197 set(haxes,'YLimMode', 'manual')198 else199 set(haxes,'XLimMode', 'auto')200 set(haxes,'YLimMode', 'auto')201 end202 if ~isfield(PlotParam.Coordinates,'CheckFixAspectRatio')&& isfield(Data,'CoordUnit')203 PlotParam.Coordinates.CheckFixAspectRatio=1;% if CoordUnit is defined, the two coordiantes should be plotted with equal scale by default204 end205 % if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)206 % set(haxes,'DataAspectRatioMode','manual')207 % set(haxes,'DataAspectRatio',[1 1 1])208 % else209 % set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio210 % end211 errormsg='';212 213 %% plot if the input field is valid214 AxeData=get(haxes,'UserData');215 if isempty(index_2D)216 plot_plane([],[],[],haxes);%removes images or vector plots if any217 else %plot 2D field218 [tild,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);219 AxeData.NbDim=2;220 if testzoomaxes && isempty(errormsg)221 [zoomaxes,PlotParamOut,tild,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);222 AxeData.ZoomAxes=zoomaxes;223 end224 end225 if isempty(index_1D)226 if ~isempty(haxes)227 plot_profile([],[],[],haxes);%228 end229 else %plot 1D field (usual graph y vs x)230 Coordinates=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),haxes,PlotParam.Coordinates);%231 if testzoomaxes232 [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);233 AxeData.ZoomAxes=zoomaxes;234 end235 if ~isempty(Coordinates)236 PlotParamOut.Coordinates=Coordinates;237 end238 PlotType='line';239 end240 % text display241 htext=findobj(hfig,'Tag','text_display');242 if ~isempty(htext)243 if isempty(index_0D)244 set(htext,'String',{''})245 else246 [errormsg]=plot_text(Data,CellVarIndex(index_0D),VarType(index_0D),htext);247 end248 end249 233 end 250 234 … … 255 239 256 240 %% update the parameters stored in AxeData 257 if ishandle(haxes) 241 if ishandle(haxes)&&( ~isempty(index_2D)|| ~isempty(index_1D)) 242 % AxeData=[]; 258 243 if isfield(PlotParamOut,'MinX') 259 244 AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX]; … … 264 249 265 250 %% update the plotted field stored in parent figure 266 267 FigData=get(hfig,'UserData'); 268 if strcmp(get(hfig,'tag'),'view_field') 269 set(hfig,'UserData',[]); % refresh user data in view_field (set by civ/TestCiv ) 270 end 271 tagaxes=get(haxes,'tag');% tag of the current plot axis 272 if isfield(FigData,tagaxes) 273 FigData.(tagaxes)=Data; 274 set(hfig,'UserData',FigData) 251 if ~isempty(index_2D)|| ~isempty(index_1D) 252 FigData=get(hfig,'UserData'); 253 % if strcmp(get(hfig,'tag'),'view_field') 254 % set(hfig,'UserData',[]); % refresh user data in view_field (set by civ/TestCiv ) 255 % end 256 tagaxes=get(haxes,'tag');% tag of the current plot axis 257 if isfield(FigData,tagaxes) 258 FigData.(tagaxes)=Data; 259 set(hfig,'UserData',FigData) 260 end 275 261 end 276 262 … … 280 266 errormsg=[]; 281 267 txt_cell={}; 268 Data={}; 282 269 for icell=1:length(CellVarIndex) 283 270 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list data.ListVarName … … 294 281 VarName=FieldData.ListVarName{VarIndex(ivar)}; 295 282 VarValue=FieldData.(VarName); 283 Data =[Data [{VarName}; num2cell(VarValue)]]; 296 284 if size(VarValue,1)~=1 297 VarValue=VarValue'; 285 VarValue=VarValue';% put the different values on a line 298 286 end 299 287 if size(VarValue,1)==1 … … 304 292 end 305 293 end 306 set(htext,'String',txt_cell) 307 set(htext,'UserData',txt_cell)% for storage during mouse display 294 if strcmp(get(htext,'Type'),'uitable') 295 get(htext,'ColumnName') 296 set(htext,'ColumnName',Data(1,:)) 297 set(htext,'Data',Data(2:end,:)) 298 else 299 set(htext,'String',txt_cell) 300 set(htext,'UserData',txt_cell)% for storage during mouse display 301 end 302 308 303 309 304 %------------------------------------------------------------------- … … 499 494 500 495 %% determine plot aspect ratio 501 if is equal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')496 if isfield(Coordinates,'CheckFixAspectRatio') && isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio') 502 497 set(haxes,'DataAspectRatioMode','manual') 503 498 set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1]) 504 499 else 505 500 set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio 506 AspectRatio=get(haxes,'DataAspectRatio') 501 AspectRatio=get(haxes,'DataAspectRatio'); 507 502 CoordinatesOut.AspectRatio=AspectRatio(1)/AspectRatio(2); 508 503 end … … 824 819 set(haxes,'DataAspectRatioMode','manual') 825 820 if isfield(PlotParam.Coordinates,'AspectRatio') 826 set(haxes,'DataAspectRatio',[PlotParam.Coordinates.AspectRatio PlotParam.Coordinates.AspectRatio PlotParam.Coordinates.AspectRatio])821 set(haxes,'DataAspectRatio',[PlotParam.Coordinates.AspectRatio 1 1]) 827 822 else 828 823 set(haxes,'DataAspectRatio',[1 1 1]) … … 887 882 % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is 888 883 % requested: 889 if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)890 set(haxes,'DataAspectRatioMode','manual')891 set(haxes,'DataAspectRatio',[1 1 1])892 end893 884 set(hima,'Tag','ima') 894 885 set(hima,'HitTest','off') … … 906 897 set(hima,'YData',AY); 907 898 end 899 908 900 % set the transparency to 0.5 if vectors are also plotted 909 901 if isfield(PlotParam.Scalar,'Opacity')&& ~isempty(PlotParam.Scalar.Opacity) … … 1129 1121 PlotParamOut.Coordinates.y_units=y_units; 1130 1122 end 1123 if isfield(PlotParam,'Coordinates') && isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1) 1124 set(haxes,'DataAspectRatioMode','manual') 1125 if isfield(PlotParam.Coordinates,'AspectRatio') 1126 set(haxes,'DataAspectRatio',[PlotParam.Coordinates.AspectRatio 1 1]) 1127 end 1128 else 1129 set(haxes,'DataAspectRatioMode','auto') 1130 end 1131 1131 %------------------------------------------------------------------- 1132 1132 % --- function for plotting vectors
Note: See TracChangeset
for help on using the changeset viewer.