Changeset 688 for trunk/src/plot_field.m
 Timestamp:
 Sep 27, 2013, 11:20:34 AM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/plot_field.m
r674 r688 738 738 end 739 739 end 740 PlotParamOut=PlotParam; % output plot parameters equal to input by default 740 741 741 742 %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%% 742 743 if isfield(PlotParam.Scalar,'ListContour')744 CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');745 else746 CheckContour=0; %default747 end748 PlotParamOut=PlotParam; %default749 743 if test_ima 744 750 745 % distinguish B/W and color images 751 746 np=size(A);%size of image … … 773 768 PlotParamOut.Scalar.CheckBW=BW; 774 769 end 770 771 % determine the plot option 'image' or 'contours' 772 if isfield(PlotParam.Scalar,'ListContour') 773 CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option 774 else 775 CheckContour=0; %default 776 end 777 775 778 %case of grey level images or contour plot 776 779 if siz==2 777 780 if ~isfield(PlotParam.Scalar,'CheckFixScalar') 778 PlotParam.Scalar.CheckFixScalar=0;% default781 PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default 779 782 end 780 783 if ~isfield(PlotParam.Scalar,'MinA') 781 PlotParam.Scalar.MinA=[];% default784 PlotParam.Scalar.MinA=[];%no min scalar threshold value set 782 785 end 783 786 if ~isfield(PlotParam.Scalar,'MaxA') 784 PlotParam.Scalar.MaxA=[];%default 785 end 786 Aline=[]; 787 if ~PlotParam.Scalar.CheckFixScalar isempty(PlotParam.Scalar.MinA)~isa(PlotParam.Scalar.MinA,'double') %correct if there is no numerical data in edit box 788 Aline=reshape(A,1,[]); 789 Aline=Aline(~isnan(A)); 790 if isempty(Aline) 787 PlotParam.Scalar.MaxA=[];%no max scalar threshold value set 788 end 789 790 % determine the min scalar value 791 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA) 792 MinA=double(PlotParam.Scalar.MinA); % min value set as input 793 else 794 MinA=double(nanmin(nanmin(A))); % min value set as min of non NaN scalar values 795 end 796 797 % error if the input scalar is NaN everywhere 798 if isnan(MinA) 791 799 errormsg='NaN input scalar or image in plot_field'; 792 800 return 793 end 794 MinA=double(min(Aline)); 795 else 796 MinA=PlotParam.Scalar.MinA; 797 end; 798 if ~PlotParam.Scalar.CheckFixScalarisempty(PlotParam.Scalar.MaxA)~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box 799 if isempty(Aline) 800 Aline=reshape(A,1,[]); 801 Aline=Aline(~isnan(A)); 802 if isempty(Aline) 803 errormsg='NaN input scalar or image in plot_field'; 804 return 805 end 806 end 807 MaxA=double(max(Aline)); 808 else 809 MaxA=PlotParam.Scalar.MaxA; 810 end; 801 end 802 803 % determine the max scalar value 804 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA) 805 MaxA=double(PlotParam.Scalar.MaxA); % max value set as input 806 else 807 MaxA=double(nanmax(nanmax(A))); % max value set as min of non NaN scalar values 808 end 809 811 810 PlotParamOut.Scalar.MinA=MinA; 812 811 PlotParamOut.Scalar.MaxA=MaxA; 813 812 PlotParamOut.Scalar.Npx=size(A,2); 814 813 PlotParamOut.Scalar.Npy=size(A,1); 814 815 815 % case of contour plot 816 816 if CheckContour 817 817 if ~isempty(hima) && ishandle(hima) 818 delete(hima) 819 end 818 delete(hima) % delete existing image 819 end 820 821 % set the contour values 820 822 if ~isfield(PlotParam.Scalar,'IncrA') 821 PlotParam.Scalar.IncrA=NaN; 822 end 823 if isempty(PlotParam.Scalar.IncrA) isnan(PlotParam.Scalar.IncrA)%  PlotParam.Scalar.AutoScal==0 823 PlotParam.Scalar.IncrA=[];% automatic contour interval 824 end 825 if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA) 826 interval=PlotParam.Scalar.IncrA; 827 else % automatic contour interval 824 828 cont=colbartick(MinA,MaxA); 825 intercont=cont(2)cont(1);%default 826 PlotParamOut.Scalar.IncrA=intercont; 827 else 828 intercont=PlotParam.Scalar.IncrA; 829 end 830 B=A; 831 abscontmin=intercont*floor(MinA/intercont); 832 abscontmax=intercont*ceil(MaxA/intercont); 833 contmin=intercont*floor(min(min(B))/intercont); 834 contmax=intercont*ceil(max(max(B))/intercont); 835 cont_pos_plus=0:intercont:contmax; 836 cont_pos_min=double(contmin):intercont:intercont; 837 cont_pos=[cont_pos_min cont_pos_plus]; 829 interval=cont(2)cont(1);%default 830 PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI 831 end 832 %B=A; 833 abscontmin=interval*floor(MinA/interval); 834 abscontmax=interval*ceil(MaxA/interval); 835 contmin=interval*floor(min(min(A))/interval); 836 contmax=interval*ceil(max(max(A))/interval); 837 cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines) 838 cont_pos_min=double(contmin):interval:interval;% negative contour values (plotted as dashed lines) 839 cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values 840 838 841 sizpx=(AX(end)AX(1))/(np(2)1); 839 842 sizpy=(AY(1)AY(end))/(np(1)1); 840 843 x_cont=AX(1):sizpx:AX(end); % pixel x coordinates for image display 841 844 y_cont=AY(1):sizpy:AY(end); % pixel x coordinates for image display 842 % axes(haxes)% set the input axes handle as current axis 843 txt=ver('MATLAB'); 844 Release=txt.Release; 845 relnumb=str2double(Release(3:4)); 846 if relnumb >= 14 847 vec=linspace(0,1,(abscontmaxabscontmin)/intercont);%define a greyscale colormap with steps intercont 845 846 %axes(haxes)% set the input axes handle as current axis 847 848 % colormap(map); 849 tag_axes=get(haxes,'Tag');% axes tag 850 Opacity=1; 851 if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity) 852 Opacity=PlotParam.Scalar.Opacity; 853 end 854 % fill the space between contours if opacity is undefined or =1 855 if isequal(Opacity,1) 856 [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours 857 set(hcontour,'Fill','on')% fill the space between contours 858 set(hcontour,'LineStyle','none') 859 hold on 860 end 861 [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k');% draw the contours for positive values as solid lines 862 hold on 863 [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'');% draw the contours for negative values as dashed lines 864 if isequal(Opacity,1) 865 set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background) 866 end 867 set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !) 868 hold off 869 870 %determine the color scale and map 871 caxis([abscontmin abscontmax]) 872 if BW 873 vec=linspace(0,1,(abscontmaxabscontmin)/interval);%define a greyscale colormap with steps interval 848 874 map=[vec' vec' vec']; 849 875 colormap(map); 850 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos); 851 set(hcontour,'Fill','on') 852 set(hcontour,'LineStyle','none') 853 hold on 854 end 855 [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k'); 856 hold on 857 [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':'); 858 set(hcontour_m,'LineColor',[1 1 1]) 859 hold off 860 caxis([abscontmin abscontmax]) 861 colormap(map); 876 else 877 colormap('default'); % default matlab colormap ('jet') 878 end 879 862 880 if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1) 863 881 set(haxes,'DataAspectRatioMode','manual') … … 868 886 end 869 887 end 870 end 871 888 else 872 889 % set colormap for image display 873 if ~CheckContour874 890 % rescale the grey levels with min and max, put a grey scale colorbar 875 B=A;891 % B=A; 876 892 if BW 877 893 vec=linspace(0,1,255);%define a linear greyscale colormap … … 879 895 colormap(map); %grey scale color map 880 896 else 881 colormap('default'); % standard fa ulse colors for div, vort , scalar fields897 colormap('default'); % standard false colors for div, vort , scalar fields 882 898 end 883 899 end … … 886 902 else 887 903 if BW 888 B=uint16(sum(A,3));889 else 890 B=uint8(A);904 A=uint16(sum(A,3)); 905 else 906 A=uint8(A); 891 907 end 892 908 MinA=0; … … 898 914 % interpolate field to increase resolution of image display 899 915 test_interp=0; 900 if size( B,3)==1 % scalar of B/W image916 if size(A,3)==1 % scalar of B/W image 901 917 test_interp=1; 902 918 if max(np) <= 64 … … 917 933 xi=linspace(AX(1),AX(2),npxy(2)); 918 934 yi=linspace(AY(1),AY(2),npxy(1)); 919 B = interp2(X,Y,double(B),xi,yi');935 A = interp2(X,Y,double(A),xi,yi'); 920 936 end 921 937 % create new image if there no image handle is found … … 923 939 tag=get(haxes,'Tag'); 924 940 if MinA<MaxA 925 hima=imagesc(AX,AY, B,[MinA MaxA]);941 hima=imagesc(AX,AY,A,[MinA MaxA]); 926 942 else % to deal with uniform field 927 hima=imagesc(AX,AY, B,[MaxA1 MaxA]);943 hima=imagesc(AX,AY,A,[MaxA1 MaxA]); 928 944 end 929 945 % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is … … 935 951 % update an existing image 936 952 else 937 set(hima,'CData', B);953 set(hima,'CData',A); 938 954 if MinA<MaxA 939 955 set(haxes,'CLim',[MinA MaxA])
Note: See TracChangeset
for help on using the changeset viewer.