Changeset 429 for trunk/src/plot_field.m


Ignore:
Timestamp:
May 22, 2012, 1:07:40 AM (12 years ago)
Author:
sommeria
Message:

improvements in object drawing and projection on points

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r428 r429  
    4848%           .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
    4949%     .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
    5051%            --scalars--
    5152%    .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
     
    143144end
    144145
    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
     147testnewfig=1;%test to create a new figure (default)
     148testzoomaxes=0;%test for the existence of a zoom secondary figure attached to the plotting axes
     149if 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
     162end
     163
     164%% create a new figure and axes if the plotting axes does not exist
     165if 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
     171else
     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
     175end
     176
     177%% set axes properties
     178if isfield(PlotParam.Coordinates,'CheckFixLimits') && isequal(PlotParam.Coordinates.CheckFixLimits,1)  %adjust the graph limits
     179    set(haxes,'XLimMode', 'manual')
     180    set(haxes,'YLimMode', 'manual')
     181else
     182    set(haxes,'XLimMode', 'auto')
     183    set(haxes,'YLimMode', 'auto')
     184end
     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
     188errormsg='';
     189PlotParamOut.Coordinates=[]; %default output
     190AxeData=get(haxes,'UserData');
     191
     192%% 2D plots
     193if isempty(index_2D)
     194    plot_plane([],[],[],haxes);%removes images or vector plots in the absence of 2D field plot
     195else  %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
     202end
     203
     204%% 1D plot (usual graph y vs x)
     205if 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
     209else %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';
     219end
     220
     221%% text display
     222if isempty(index_2D) && isempty(index_1D)%text display alone
     223    htext=findobj(hfig,'Tag','TableDisplay');
     224else  %text display added to plot
    151225    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
     226end
     227if ~isempty(htext)
    155228    if isempty(index_0D)
    156229        set(htext,'String',{''})
     
    158231        [errormsg]=plot_text(Data,CellVarIndex(index_0D),VarType(index_0D),htext);
    159232    end
    160     haxes=[];
    161 end
    162 
    163 %% test axes and figure
    164 if ~isempty(index_2D)|| ~isempty(index_1D)%  plot
    165     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 axes
    167     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                     end
    177                 end
    178             end
    179         end
    180     end
    181     % create a new figure and axes if the plotting axes does not exist
    182     if testnewfig
    183         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_his
    188     else
    189         hfig=get(haxes,'parent');
    190         set(0,'CurrentFigure',hfig)% the parent of haxes becomes the current figure
    191         set(hfig,'CurrentAxes',haxes)%  haxes becomes the current axes of the parent figure
    192     end
    193    
    194     %% set axes properties
    195     if isfield(PlotParam.Coordinates,'CheckFixLimits') && isequal(PlotParam.Coordinates.CheckFixLimits,1)  %adjust the graph limits
    196         set(haxes,'XLimMode', 'manual')
    197         set(haxes,'YLimMode', 'manual')
    198     else
    199         set(haxes,'XLimMode', 'auto')
    200         set(haxes,'YLimMode', 'auto')
    201     end
    202     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 default
    204     end
    205 %     if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)
    206 %         set(haxes,'DataAspectRatioMode','manual')
    207 %         set(haxes,'DataAspectRatio',[1 1 1])
    208 %     else
    209 %         set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
    210 %     end
    211     errormsg='';
    212    
    213     %% plot if the input field is valid
    214     AxeData=get(haxes,'UserData');
    215     if isempty(index_2D)
    216         plot_plane([],[],[],haxes);%removes images or vector plots if any
    217     else  %plot 2D field
    218         [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         end
    224     end
    225     if isempty(index_1D)
    226         if ~isempty(haxes)
    227             plot_profile([],[],[],haxes);%
    228         end
    229     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 testzoomaxes
    232             [zoomaxes,Coordinates]=plot_profile(Data,CellVarIndex(index_1D),VarType(index_1D),zoomaxes,PlotParam.Coordinates);
    233             AxeData.ZoomAxes=zoomaxes;
    234         end
    235         if ~isempty(Coordinates)
    236             PlotParamOut.Coordinates=Coordinates;
    237         end
    238         PlotType='line';
    239     end
    240     % text display
    241     htext=findobj(hfig,'Tag','text_display');
    242     if ~isempty(htext)
    243         if isempty(index_0D)
    244             set(htext,'String',{''})
    245         else
    246             [errormsg]=plot_text(Data,CellVarIndex(index_0D),VarType(index_0D),htext);
    247         end
    248     end
    249233end
    250234
     
    255239
    256240%% update the parameters stored in AxeData
    257 if ishandle(haxes)
     241if ishandle(haxes)&&( ~isempty(index_2D)|| ~isempty(index_1D))
     242%     AxeData=[];
    258243    if isfield(PlotParamOut,'MinX')
    259244        AxeData.RangeX=[PlotParamOut.MinX PlotParamOut.MaxX];%'[PlotParamOut.MinX PlotParamOut.MaxX];
     
    264249
    265250%% 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)
     251if ~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
    275261end
    276262
     
    280266errormsg=[];
    281267txt_cell={};
     268Data={};
    282269for icell=1:length(CellVarIndex)
    283270    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list data.ListVarName
     
    294281            VarName=FieldData.ListVarName{VarIndex(ivar)};
    295282            VarValue=FieldData.(VarName);
     283            Data =[Data [{VarName}; num2cell(VarValue)]];
    296284            if size(VarValue,1)~=1
    297                 VarValue=VarValue';
     285                VarValue=VarValue';% put the different values on a line
    298286            end
    299287            if size(VarValue,1)==1
     
    304292    end
    305293end
    306 set(htext,'String',txt_cell)
    307 set(htext,'UserData',txt_cell)% for storage during mouse display
     294if strcmp(get(htext,'Type'),'uitable')
     295    get(htext,'ColumnName')
     296    set(htext,'ColumnName',Data(1,:))
     297    set(htext,'Data',Data(2:end,:))
     298else
     299    set(htext,'String',txt_cell)
     300    set(htext,'UserData',txt_cell)% for storage during mouse display
     301end
     302
    308303
    309304%-------------------------------------------------------------------
     
    499494
    500495%% determine plot aspect ratio
    501 if isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')
     496if isfield(Coordinates,'CheckFixAspectRatio') && isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')
    502497    set(haxes,'DataAspectRatioMode','manual')
    503498    set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1])
    504499else
    505500    set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
    506     AspectRatio=get(haxes,'DataAspectRatio')
     501    AspectRatio=get(haxes,'DataAspectRatio');
    507502    CoordinatesOut.AspectRatio=AspectRatio(1)/AspectRatio(2);
    508503end
     
    824819                set(haxes,'DataAspectRatioMode','manual')
    825820                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])
    827822                else
    828823                    set(haxes,'DataAspectRatio',[1 1 1])
     
    887882            % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is
    888883            % 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             end
    893884            set(hima,'Tag','ima')
    894885            set(hima,'HitTest','off')
     
    906897            set(hima,'YData',AY);
    907898        end
     899
    908900        % set the transparency to 0.5 if vectors are also plotted
    909901        if isfield(PlotParam.Scalar,'Opacity')&& ~isempty(PlotParam.Scalar.Opacity)
     
    11291121    PlotParamOut.Coordinates.y_units=y_units;
    11301122end
     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
    11311131%-------------------------------------------------------------------
    11321132% --- function for plotting vectors
Note: See TracChangeset for help on using the changeset viewer.