Changeset 428 for trunk/src/plot_field.m
 Timestamp:
 May 19, 2012, 12:38:14 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/plot_field.m
r426 r428 47 47 % .Coordinates: coordinate parameters: 48 48 % .CheckFixLimits:=0 (default) adjust axes limit to the X,Y data, =1: preserves the previous axes limits 49 % .Coordinates.CheckFix Equal: =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. 50 50 % scalars 51 51 % .Scalar.MaxA: upper bound (saturation color) for the scalar representation, max(field) by default … … 200 200 set(haxes,'YLimMode', 'auto') 201 201 end 202 if ~isfield(PlotParam.Coordinates,'CheckFix Equal')&& isfield(Data,'CoordUnit')203 PlotParam.Coordinates.CheckFix Equal=1;% if CoordUnit is defined, the two coordiantes should be plotted with equal scale by default204 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 else209 set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio210 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 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 211 errormsg=''; 212 212 … … 471 471 end 472 472 htitle=title(title_str); 473 txt=ver('MATLAB');474 Release=txt.Release;475 relnumb=str2double(Release(3:4));476 if relnumb >= 14477 478 end473 % 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 479 479 end 480 480 … … 496 496 CoordinatesOut.MinY=min(YMin_cell); 497 497 CoordinatesOut.MaxY=max(YMax_cell); 498 end 499 500 %% determine plot aspect ratio 501 if isequal(Coordinates.CheckFixAspectRatio,1)&&isfield(Coordinates,'AspectRatio') 502 set(haxes,'DataAspectRatioMode','manual') 503 set(haxes,'DataAspectRatio',[Coordinates.AspectRatio 1 1]) 504 else 505 set(haxes,'DataAspectRatioMode','auto')%automatic aspect ratio 506 AspectRatio=get(haxes,'DataAspectRatio') 507 CoordinatesOut.AspectRatio=AspectRatio(1)/AspectRatio(2); 498 508 end 499 509 … … 705 715 siz=numel(np); 706 716 if siz>3 707 errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions'];708 717 errormsg=['unrecognized scalar type: ' num2str(siz) ' dimensions']; 718 return 709 719 end 710 720 if siz==3 … … 725 735 BW=(siz==2) && (isa(A,'uint8') isa(A,'uint16'));% non color images represented in gray scale by default 726 736 PlotParamOut.Scalar.CheckBW=BW; 727 end 737 end 728 738 %case of grey level images or contour plot 729 if siz==2 739 if siz==2 730 740 if ~isfield(PlotParam.Scalar,'CheckFixScalar') 731 741 PlotParam.Scalar.CheckFixScalar=0;%default … … 742 752 Aline=Aline(~isnan(A)); 743 753 if isempty(Aline) 744 754 errormsg='NaN input scalar or image in plot_field'; 745 755 return 746 756 end … … 748 758 else 749 759 MinA=PlotParam.Scalar.MinA; 750 end; 760 end; 751 761 if ~PlotParam.Scalar.CheckFixScalarisempty(PlotParam.Scalar.MaxA)~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box 752 762 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 return758 end763 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 759 769 end 760 770 MaxA=double(max(Aline)); 761 771 else 762 MaxA=PlotParam.Scalar.MaxA; 763 end; 772 MaxA=PlotParam.Scalar.MaxA; 773 end; 764 774 PlotParamOut.Scalar.MinA=MinA; 765 775 PlotParamOut.Scalar.MaxA=MaxA; … … 777 787 PlotParamOut.Scalar.IncrA=intercont; 778 788 else 779 intercont=PlotParam.Scalar.IncrA;780 end 781 B=A; 789 intercont=PlotParam.Scalar.IncrA; 790 end 791 B=A; 782 792 abscontmin=intercont*floor(MinA/intercont); 783 793 abscontmax=intercont*ceil(MaxA/intercont); … … 789 799 sizpx=(AX(end)AX(1))/(np(2)1); 790 800 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 792 802 y_cont=AY(1):sizpy:AY(end); % pixel x coordinates for image display 793 % axes(haxes)% set the input axes handle as current axis794 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; 796 806 relnumb=str2double(Release(3:4)); 797 807 if relnumb >= 14 798 808 vec=linspace(0,1,(abscontmaxabscontmin)/intercont);%define a greyscale colormap with steps intercont 799 809 map=[vec' vec' vec']; 800 810 colormap(map); 801 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos); 811 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos); 802 812 set(hcontour,'Fill','on') 803 813 set(hcontour,'LineStyle','none') … … 809 819 set(hcontour_m,'LineColor',[1 1 1]) 810 820 hold off 811 caxis([abscontmin abscontmax]) 821 caxis([abscontmin abscontmax]) 812 822 colormap(map); 813 if isfield(PlotParam.Coordinates,'CheckFixEqual') && isequal(PlotParam.Coordinates.CheckFixEqual,1)823 if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1) 814 824 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 817 831 end 818 832 … … 824 838 vec=linspace(0,1,255);%define a linear greyscale colormap 825 839 map=[vec' vec' vec']; 826 colormap(map); %grey scale color map 840 colormap(map); %grey scale color map 827 841 else 828 colormap('default'); % standard faulse colors for div, vort , scalar fields 842 colormap('default'); % standard faulse colors for div, vort , scalar fields 829 843 end 830 844 end 831 845 832 % case of color images833 else 846 % case of color images 847 else 834 848 if BW 835 849 B=uint16(sum(A,3)); … … 842 856 843 857 % display usual image 844 if ~CheckContour 858 if ~CheckContour 845 859 % interpolate field to increase resolution of image display 846 860 test_interp=1; 847 if max(np) <= 64 861 if max(np) <= 64 848 862 npxy=8*np;% increase the resolution 8 times 849 elseif max(np) <= 128 863 elseif max(np) <= 128 850 864 npxy=4*np;% increase the resolution 4 times 851 elseif max(np) <= 256 865 elseif max(np) <= 256 852 866 npxy=2*np;% increase the resolution 2 times 853 867 else … … 855 869 test_interp=0; % no interpolation done 856 870 end 857 if test_interp==1%if we interpolate 871 if test_interp==1%if we interpolate 858 872 x=linspace(AX(1),AX(2),np(2)); 859 873 y=linspace(AY(1),AY(2),np(1)); … … 862 876 yi=linspace(AY(1),AY(2),npxy(1)); 863 877 B = interp2(X,Y,double(B),xi,yi'); 864 end 878 end 865 879 % create new image if there no image handle is found 866 if isempty(hima) 880 if isempty(hima) 867 881 tag=get(haxes,'Tag'); 868 882 if MinA<MaxA … … 871 885 hima=imagesc(AX,AY,B,[MaxA1 MaxA]); 872 886 end 873 % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFix Equalis887 % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is 874 888 % requested: 875 if isfield(PlotParam.Coordinates,'CheckFixEqual') && isequal(PlotParam.Coordinates.CheckFixEqual,1)889 if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1) 876 890 set(haxes,'DataAspectRatioMode','manual') 877 891 set(haxes,'DataAspectRatio',[1 1 1]) 878 end892 end 879 893 set(hima,'Tag','ima') 880 894 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 !!!) 882 896 uistack(hima, 'bottom') 883 % update an existing image897 % update an existing image 884 898 else 885 899 set(hima,'CData',B); … … 893 907 end 894 908 % 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 899 918 end 900 919 end … … 904 923 if siz==2 && exist('PosColorbar','var')&& ~isempty(PosColorbar) 905 924 if isempty(hcol)~ishandle(hcol) 906 925 hcol=colorbar;%create new colorbar 907 926 end 908 927 if length(PosColorbar)==4 909 set(hcol,'Position',PosColorbar)910 end 928 set(hcol,'Position',PosColorbar) 929 end 911 930 %YTick=0;%default 912 931 if MaxA>MinA 913 932 if CheckContour 914 933 colbarlim=get(hcol,'YLim'); 915 scale_bar=(colbarlim(2)colbarlim(1))/(abscontmaxabscontmin); 934 scale_bar=(colbarlim(2)colbarlim(1))/(abscontmaxabscontmin); 916 935 YTick=cont_pos(2:end1); 917 936 YTick_scaled=colbarlim(1)+scale_bar*(YTickabscontmin); … … 926 945 set(hcol,'YLim',[MinA MaxA]) 927 946 YTick=colbartick(MinA,MaxA); 928 set(hcol,'YTick',YTick) 947 set(hcol,'YTick',YTick) 929 948 else 930 949 hi=get(hcol,'children'); … … 934 953 set(hi,'YData',[MinA MaxA]) 935 954 set(hi,'CData',(1:64)') 936 YTick=colbartick(MinA,MaxA); 955 YTick=colbartick(MinA,MaxA); 937 956 set(hcol,'YLim',[MinA MaxA]) 938 957 set(hcol,'YTick',YTick) … … 941 960 end 942 961 elseif ishandle(hcol) 943 delete(hcol); %erase existing colorbar if not needed 962 delete(hcol); %erase existing colorbar if not needed 944 963 end 945 964 else%no scalar plot 946 if ~isempty(hima) && ishandle(hima) 965 if ~isempty(hima) && ishandle(hima) 947 966 delete(hima) 948 967 end 949 968 if ~isempty(hcol)&& ishandle(hcol) 950 delete(hcol)969 delete(hcol) 951 970 end 952 971 PlotParamOut=rmfield(PlotParamOut,'Scalar');
Note: See TracChangeset
for help on using the changeset viewer.