Changeset 193 for trunk/src/plot_field.m


Ignore:
Timestamp:
Feb 20, 2011, 10:42:19 AM (13 years ago)
Author:
sommeria
Message:

improves the use of get_field, no projection object by default in uvmat( allows usual 1D plots),

various bug repairs, elimination of get_plot_handles.m (not useful)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r192 r193  
    134134if testnewfig
    135135    hfig=figure;
    136 %     if isfield(PlotParam,'text_display_1') && ishandle(PlotParam.text_display_1)
    137 %         set(hfig,'UserData',PlotParam)
    138 %     end
    139136    set(hfig,'Units','normalized')
    140 %     set(hfig,'WindowButtonDownFcn','mouse_down')
    141 %     set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action function
    142 %     set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse action function
    143137    haxes=axes;
    144138    set(haxes,'position',[0.13,0.2,0.775,0.73])
     
    161155    %% check the cells of fields :
    162156    [CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Data);
    163 
    164157    if ~isempty(errormsg)
    165158        msgbox_uvmat('ERROR',['input of plot_field/find_field_indices: ' errormsg]);
     
    202195errormsg=[];
    203196AxeData=get(haxes,'UserData');
     197if isempty(index_2D)
     198    plot_plane([],[],[],haxes);%removes images or vector plots if any
     199else
     200    [xx,PlotParamOut,PlotType,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),haxes,PlotParam,PosColorbar);
     201    AxeData.NbDim=2;
     202    if testzoomaxes && isempty(errormsg)
     203        [zoomaxes,PlotParamOut,xx,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
     204        AxeData.ZoomAxes=zoomaxes;
     205    end
     206    %remove coordinates variables from 1D plot
     207    for ivar=1:length(index_1D)
     208        if isequal(CellVarIndex{index_1D(ivar)},VarType{index_1D(ivar)}.coord)
     209            index_1D(ivar)=0;
     210        end
     211    end
     212    index_1D=find(index_1D);
     213end
     214
    204215if isempty(index_1D)
    205216     plot_profile([],[],[],haxes);%
     
    211222        end
    212223        PlotType='line';
    213 end
    214 
    215 if isempty(index_2D)
    216     plot_plane([],[],[],haxes);%removes images or vector plots if any
    217 else
    218          [xx,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,xx,errormsg]=plot_plane(Data,CellVarIndex(index_2D),VarType(index_2D),zoomaxes,PlotParam,PosColorbar);
    222                 AxeData.ZoomAxes=zoomaxes;
    223             end
    224224end
    225225htext=findobj(hfig,'Tag','text_display');
     
    374374    else
    375375        coord_x_index_cell=VarType{icell}.coord(1);
    376          if isequal(coord_x_index_cell,0)
     376        if isequal(coord_x_index_cell,0)
    377377             continue  % the cell has no abscissa, skip it
    378          end
    379 %         if ~isempty(coord_x_index)&&~isequal(coord_x_index_cell,coord_x_index)
    380 %             %continue %all the selected variables must have the same first dimension
    381 %         else
    382 %             coord_x_index=coord_x_index_cell;
    383 %         end
    384           coord_x_index=coord_x_index_cell;
     378        end
     379        coord_x_index=coord_x_index_cell;
    385380    end
    386381    testplot=ones(size(data.ListVarName));%default test for plotted variables
     
    393388    end
    394389    eval(['coord_x{icell}=data.' data.ListVarName{coord_x_index} ';']);%coordinate variable set as coord_x
     390    XMin(icell)=min(coord_x{icell});
     391    XMax(icell)=max(coord_x{icell});
    395392    testplot(coord_x_index)=0;
    396393    if ~isempty(VarType{icell}.ancillary')
     
    425422            end
    426423            eval(['data.' VarName '=squeeze(data.' VarName ');'])
     424            eval(['YMin(ivar)=min(data.' VarName ');'])
     425            eval(['YMax(ivar)=max(data.' VarName ');'])
    427426            plotstr=[plotstr 'coord_x{' num2str(icell) '},data.' VarName ',' charplot_0 ','];
    428427            eval(['nbcomponent2=size(data.' VarName ',2);']);
     
    431430                coord_x{icell}=linspace(coord_x{icell}(1),coord_x{icell}(2),nbcomponent1);
    432431            end
    433             %eval(['varmean=mean(double(data.' VarName '));']);%mean value
    434             %textmean=[textmean; {[VarName 'mean= ' num2str(varmean,4)]}];
    435432            if nbcomponent1==1|| nbcomponent2==1
    436433                legend_str=[legend_str {VarName}]; %variable with one component
     
    442439        end
    443440    end
     441    YMin_cell(icell)=min(YMin);
     442    YMax_cell(icell)=max(YMax);
    444443end
    445444
     
    447446if test_newplot && ~isequal(plotstr,'hhh=plot(') 
    448447    set(hfig,'CurrentAxes',haxes)
    449     tag=get(haxes,'tag');
    450    
     448    tag=get(haxes,'tag');   
    451449    %%%
    452450    plotstr=[plotstr '''tag'',''plot_line'');'];   
    453451    eval(plotstr)                  %execute plot (instruction  plotstr)
    454452    %%%
    455    
    456453    set(haxes,'tag',tag)
    457454    grid(haxes, 'on')
     
    499496end
    500497
     498%% determine axes bounds
     499 fix_lim=isfield(PlotParam,'FixLimits') && PlotParam.FixLimits;
     500if fix_lim
     501    if ~isfield(PlotParam,'MinX')||~isfield(PlotParam,'MaxX')||~isfield(PlotParam,'MinY')||~isfield(PlotParam,'MaxY')
     502        fix_lim=0; %free limits if lits are not set,
     503    end  %else PlotParamOut.XMin =PlotParam.XMin...
     504end
     505if ~fix_lim
     506    PlotParamOut.MinX=min(XMin);
     507    PlotParamOut.MaxX=max(XMax);
     508    PlotParamOut.MinY=min(YMin_cell);
     509    PlotParamOut.MaxY=max(YMax_cell);
     510end
    501511
    502512%-------------------------------------------------------------------
     
    521531hcol=findobj(hfig,'Tag','Colorbar'); %look for colorbar axes
    522532hima=findobj(haxes,'Tag','ima');% search existing image in the current axes
    523 errormsg=[];%default
     533errormsg='';%default
    524534test_ima=0; %default: test for image or map plot
    525535test_vec=0; %default: test for vector plots
     
    661671            end
    662672            if test_interp_X 
    663                 npxy(1)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
     673                npxy(2)=max([256 floor((AX(end)-AX(1))/DAX_min) floor((AX(end)-AX(1))/DAX_max)]);
    664674                xI=linspace(AX(1),AX(end),npxy(2));   
    665675                if ~test_interp_Y
     
    10331043
    10341044%store the coordinate extrema occupied by the field
    1035 Data
    10361045if ~isempty(Data)
    10371046    fix_lim=isfield(PlotParam,'FixLimits') && PlotParam.FixLimits;
     
    10411050        end  %else PlotParamOut.XMin =PlotParam.XMin...
    10421051    end
    1043     'TESTfix'
    1044     fix_lim
    10451052    if ~fix_lim
    10461053        XMin=[];
     
    11101117rot=alpha*[cos(theta) -sin(theta); sin(theta) cos(theta)]';
    11111118%find the existing lines
    1112 %h=findobj(gca,'Type','Line');% search existing lines in the current axes
    11131119h=findobj(haxes,'Tag','vel');% search existing lines in the current axes
    11141120sizh=size(h);
    11151121set(h,'EraseMode','xor');
    11161122set(haxes,'NextPlot','replacechildren');
    1117      
     1123
    11181124%drawnow
    11191125%create lines (if no lines) or modify them
     
    11251131
    11261132for icolor=1:ncolor
    1127     %determine the line positions for each color icolor 
     1133    %determine the line positions for each color icolor
    11281134    ind=find(col_vec==icolor);
    11291135    xc=x(ind);
     
    11341140    xN=NaN*ones(size(xc));
    11351141    matx=[xc(:)-uc(:)/2 xc(:)+uc(:)/2 xN(:)]';
    1136 %     matx=[xc(:) xc(:)+uc(:) xN(:)]';
     1142    %     matx=[xc(:) xc(:)+uc(:) xN(:)]';
    11371143    matx=reshape(matx,1,3*n(2));
    11381144    maty=[yc(:)-vc(:)/2 yc(:)+vc(:)/2 xN(:)]';
    1139 %     maty=[yc(:) yc(:)+vc(:) xN(:)]';
     1145    %     maty=[yc(:) yc(:)+vc(:) xN(:)]';
    11401146    maty=reshape(maty,1,3*n(2));
    11411147   
     
    11491155    y2=yc+vc/2;
    11501156    y3=yc+vc/2-arrowmoins(2,:);
    1151 %     x1=xc+uc-arrowplus(1,:);
    1152 %     x2=xc+uc;
    1153 %     x3=xc+uc-arrowmoins(1,:);
    1154 %     y1=yc+vc-arrowplus(2,:);
    1155 %     y2=yc+vc;
    1156 %     y3=yc+vc-arrowmoins(2,:);
    11571157    matxar=[x1(:) x2(:) x3(:) xN(:)]';
    11581158    matxar=reshape(matxar,1,4*n(2));
     
    11601160    matyar=reshape(matyar,1,4*n(2));
    11611161    %draw the line or modify the existing ones
    1162   %    hx = [x1;x2;x3];
    1163   %    hy = [y1;y2;y3];
    1164     tri=reshape(1:3*length(uc),3,[])';
    1165     %d = tri(:,[1 2 3 1])';
    1166    
     1162    tri=reshape(1:3*length(uc),3,[])';   
    11671163    isn=isnan(colorlist(icolor,:));%test if color NaN
    11681164    if 2*icolor > sizh(1) %if icolor exceeds the number of existing ones
    1169         %axes(haxes)
    1170       %  hfig=get(haxes,'parent');
    1171 %         axes(haxes)
    1172       %  set(0,'CurrentFigure',hfig)
    1173        % set(hfig,'CurrentAxes',haxes)
    11741165        if ~isn(1) %if the vectors are visible color not nan
    11751166            if n(2)>0
     
    11771168                line(matx,maty,'Color',colorlist(icolor,:),'Tag','vel');% plot new lines
    11781169                line(matxar,matyar,'Color',colorlist(icolor,:),'Tag','vel');% plot arrows
    1179 %                 fill(hx(d),hy(d),colorlist(icolor,:),'EdgeColor','none','
    1180 %                 Tag','Vel');
    1181           end
     1170            end
    11821171        end
    11831172    else
    1184         if isn(1) 
     1173        if isn(1)
    11851174            delete(h(2*icolor-1))
    11861175            delete(h(2*icolor))
     
    11931182            set(h(2*icolor),'EraseMode','xor');
    11941183        end
    1195      end
     1184    end
    11961185end
    11971186if sizh(1) > 2*ncolor
Note: See TracChangeset for help on using the changeset viewer.