Changeset 428 for trunk/src/plot_field.m


Ignore:
Timestamp:
May 19, 2012, 12:38:14 PM (12 years ago)
Author:
sommeria
Message:

bugs fixed. Introduction of transparency and axis aspect ratio in uvmat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r426 r428  
    4747%     .Coordinates: coordinate parameters:
    4848%           .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits
    49 %     .Coordinates.CheckFixEqual: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.
     49%     .Coordinates.CheckFixAspectRatio: =0 (default):automatic adjustment of the graph, keep 1 to 1 aspect ratio for x and y scales.
    5050%            --scalars--
    5151%    .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default
     
    200200        set(haxes,'YLimMode', 'auto')
    201201    end
    202     if ~isfield(PlotParam.Coordinates,'CheckFixEqual')&& isfield(Data,'CoordUnit')
    203         PlotParam.Coordinates.CheckFixEqual=1;% if CoordUnit is defined, the two coordiantes should be plotted with equal scale by default
    204     end
    205     if isfield(PlotParam.Coordinates,'CheckFixEqual') && isequal(PlotParam.Coordinates.CheckFixEqual,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
     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
    211211    errormsg='';
    212212   
     
    471471    end
    472472    htitle=title(title_str);
    473     txt=ver('MATLAB');
    474     Release=txt.Release;
    475     relnumb=str2double(Release(3:4));
    476     if relnumb >= 14
    477         set(htitle,'Interpreter','none')% desable tex interpreter
    478     end
     473%     txt=ver('MATLAB');
     474%     Release=txt.Release;
     475%     relnumb=str2double(Release(3:4));
     476%     if relnumb >= 14
     477    set(htitle,'Interpreter','none')% desable tex interpreter
     478%     end
    479479end
    480480
     
    496496    CoordinatesOut.MinY=min(YMin_cell);
    497497    CoordinatesOut.MaxY=max(YMax_cell);
     498end
     499
     500%% determine plot aspect ratio
     501if isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio')
     502    set(haxes,'DataAspectRatioMode','manual')
     503    set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1])
     504else
     505    set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio
     506    AspectRatio=get(haxes,'DataAspectRatio')
     507    CoordinatesOut.AspectRatio=AspectRatio(1)/AspectRatio(2);
    498508end
    499509
     
    705715    siz=numel(np);
    706716    if siz>3
    707        errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];
    708             return
     717        errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];
     718        return
    709719    end
    710720    if siz==3
     
    725735        BW=(siz==2) && (isa(A,'uint8')|| isa(A,'uint16'));% non color images represented in gray scale by default
    726736        PlotParamOut.Scalar.CheckBW=BW;
    727     end 
     737    end
    728738    %case of grey level images or contour plot
    729     if siz==2 
     739    if siz==2
    730740        if ~isfield(PlotParam.Scalar,'CheckFixScalar')
    731741            PlotParam.Scalar.CheckFixScalar=0;%default
     
    742752            Aline=Aline(~isnan(A));
    743753            if isempty(Aline)
    744                  errormsg='NaN input scalar or image in plot_field';
     754                errormsg='NaN input scalar or image in plot_field';
    745755                return
    746756            end
     
    748758        else
    749759            MinA=PlotParam.Scalar.MinA;
    750         end; 
     760        end;
    751761        if ~PlotParam.Scalar.CheckFixScalar||isempty(PlotParam.Scalar.MaxA)||~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
    752762            if isempty(Aline)
    753                Aline=reshape(A,1,[]);
    754                Aline=Aline(~isnan(A));
    755                if isempty(Aline)
    756                  errormsg='NaN input scalar or image in plot_field';
    757                 return
    758                end
     763                Aline=reshape(A,1,[]);
     764                Aline=Aline(~isnan(A));
     765                if isempty(Aline)
     766                    errormsg='NaN input scalar or image in plot_field';
     767                    return
     768                end
    759769            end
    760770            MaxA=double(max(Aline));
    761771        else
    762             MaxA=PlotParam.Scalar.MaxA; 
    763         end; 
     772            MaxA=PlotParam.Scalar.MaxA;
     773        end;
    764774        PlotParamOut.Scalar.MinA=MinA;
    765775        PlotParamOut.Scalar.MaxA=MaxA;
     
    777787                PlotParamOut.Scalar.IncrA=intercont;
    778788            else
    779                intercont=PlotParam.Scalar.IncrA;
    780             end
    781             B=A;           
     789                intercont=PlotParam.Scalar.IncrA;
     790            end
     791            B=A;
    782792            abscontmin=intercont*floor(MinA/intercont);
    783793            abscontmax=intercont*ceil(MaxA/intercont);
     
    789799            sizpx=(AX(end)-AX(1))/(np(2)-1);
    790800            sizpy=(AY(1)-AY(end))/(np(1)-1);
    791             x_cont=AX(1):sizpx:AX(end); % pixel x coordinates for image display 
     801            x_cont=AX(1):sizpx:AX(end); % pixel x coordinates for image display
    792802            y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
    793            % axes(haxes)% set the input axes handle as current axis
    794     txt=ver('MATLAB');
    795     Release=txt.Release;
     803            % axes(haxes)% set the input axes handle as current axis
     804            txt=ver('MATLAB');
     805            Release=txt.Release;
    796806            relnumb=str2double(Release(3:4));
    797807            if relnumb >= 14
    798                     vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
     808                vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
    799809                map=[vec' vec' vec'];
    800810                colormap(map);
    801                 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);       
     811                [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
    802812                set(hcontour,'Fill','on')
    803813                set(hcontour,'LineStyle','none')
     
    809819            set(hcontour_m,'LineColor',[1 1 1])
    810820            hold off
    811             caxis([abscontmin abscontmax]) 
     821            caxis([abscontmin abscontmax])
    812822            colormap(map);
    813                        if isfield(PlotParam.Coordinates,'CheckFixEqual') && isequal(PlotParam.Coordinates.CheckFixEqual,1)
     823            if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)
    814824                set(haxes,'DataAspectRatioMode','manual')
    815                 set(haxes,'DataAspectRatio',[1 1 1])
    816            end
     825                if isfield(PlotParam.Coordinates,'AspectRatio')
     826                    set(haxes,'DataAspectRatio',[PlotParam.Coordinates.AspectRatio PlotParam.Coordinates.AspectRatio PlotParam.Coordinates.AspectRatio])
     827                else
     828                    set(haxes,'DataAspectRatio',[1 1 1])
     829                end
     830            end
    817831        end
    818832       
     
    824838                vec=linspace(0,1,255);%define a linear greyscale colormap
    825839                map=[vec' vec' vec'];
    826                 colormap(map);  %grey scale color map 
     840                colormap(map);  %grey scale color map
    827841            else
    828                 colormap('default'); % standard faulse colors for div, vort , scalar fields 
     842                colormap('default'); % standard faulse colors for div, vort , scalar fields
    829843            end
    830844        end
    831845       
    832     % case of color images
    833     else 
     846        % case of color images
     847    else
    834848        if BW
    835849            B=uint16(sum(A,3));
     
    842856   
    843857    % display usual image
    844     if ~CheckContour     
     858    if ~CheckContour
    845859        % interpolate field to increase resolution of image display
    846860        test_interp=1;
    847         if max(np) <= 64 
     861        if max(np) <= 64
    848862            npxy=8*np;% increase the resolution 8 times
    849         elseif max(np) <= 128 
     863        elseif max(np) <= 128
    850864            npxy=4*np;% increase the resolution 4 times
    851         elseif max(np) <= 256 
     865        elseif max(np) <= 256
    852866            npxy=2*np;% increase the resolution 2 times
    853867        else
     
    855869            test_interp=0; % no interpolation done
    856870        end
    857         if test_interp==1%if we interpolate   
     871        if test_interp==1%if we interpolate
    858872            x=linspace(AX(1),AX(2),np(2));
    859873            y=linspace(AY(1),AY(2),np(1));
     
    862876            yi=linspace(AY(1),AY(2),npxy(1));
    863877            B = interp2(X,Y,double(B),xi,yi');
    864         end           
     878        end
    865879        % create new image if there  no image handle is found
    866         if isempty(hima) 
     880        if isempty(hima)
    867881            tag=get(haxes,'Tag');
    868882            if MinA<MaxA
     
    871885                hima=imagesc(AX,AY,B,[MaxA-1 MaxA]);
    872886            end
    873             % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixEqual is
     887            % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is
    874888            % requested:
    875            if isfield(PlotParam.Coordinates,'CheckFixEqual') && isequal(PlotParam.Coordinates.CheckFixEqual,1)
     889            if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)
    876890                set(haxes,'DataAspectRatioMode','manual')
    877891                set(haxes,'DataAspectRatio',[1 1 1])
    878            end
     892            end
    879893            set(hima,'Tag','ima')
    880894            set(hima,'HitTest','off')
    881             set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)     
     895            set(haxes,'Tag',tag);%preserve the axes tag (removed by image fct !!!)
    882896            uistack(hima, 'bottom')
    883         % update an existing image
     897            % update an existing image
    884898        else
    885899            set(hima,'CData',B);
     
    893907        end
    894908        % set the transparency to 0.5 if vectors are also plotted
    895         if test_vec
    896             set(hima,'AlphaData',0.5)
    897         else
    898             set(hima,'AlphaData',1)
     909        if isfield(PlotParam.Scalar,'Opacity')&& ~isempty(PlotParam.Scalar.Opacity)
     910            set(hima,'AlphaData',PlotParam.Scalar.Opacity)
     911        else
     912            if test_vec
     913                set(hima,'AlphaData',0.5)%set opacity to 0.5 by default in the presence of vectors
     914                PlotParamOut.Scalar.Opacity=0.5;
     915            else
     916                set(hima,'AlphaData',1)% full opacity (no transparency) by default
     917            end
    899918        end
    900919    end
     
    904923    if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar)
    905924        if isempty(hcol)||~ishandle(hcol)
    906              hcol=colorbar;%create new colorbar
     925            hcol=colorbar;%create new colorbar
    907926        end
    908927        if length(PosColorbar)==4
    909                  set(hcol,'Position',PosColorbar)           
    910         end 
     928            set(hcol,'Position',PosColorbar)
     929        end
    911930        %YTick=0;%default
    912931        if MaxA>MinA
    913932            if CheckContour
    914933                colbarlim=get(hcol,'YLim');
    915                 scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);               
     934                scale_bar=(colbarlim(2)-colbarlim(1))/(abscontmax-abscontmin);
    916935                YTick=cont_pos(2:end-1);
    917936                YTick_scaled=colbarlim(1)+scale_bar*(YTick-abscontmin);
     
    926945                set(hcol,'YLim',[MinA MaxA])
    927946                YTick=colbartick(MinA,MaxA);
    928                 set(hcol,'YTick',YTick)               
     947                set(hcol,'YTick',YTick)
    929948            else
    930949                hi=get(hcol,'children');
     
    934953                set(hi,'YData',[MinA MaxA])
    935954                set(hi,'CData',(1:64)')
    936                 YTick=colbartick(MinA,MaxA); 
     955                YTick=colbartick(MinA,MaxA);
    937956                set(hcol,'YLim',[MinA MaxA])
    938957                set(hcol,'YTick',YTick)
     
    941960        end
    942961    elseif ishandle(hcol)
    943         delete(hcol); %erase existing colorbar if not needed 
     962        delete(hcol); %erase existing colorbar if not needed
    944963    end
    945964else%no scalar plot
    946     if ~isempty(hima) && ishandle(hima) 
     965    if ~isempty(hima) && ishandle(hima)
    947966        delete(hima)
    948967    end
    949968    if ~isempty(hcol)&& ishandle(hcol)
    950        delete(hcol)
     969        delete(hcol)
    951970    end
    952971    PlotParamOut=rmfield(PlotParamOut,'Scalar');
Note: See TracChangeset for help on using the changeset viewer.