Changeset 822 for trunk/src/plot_field.m
- Timestamp:
- Oct 10, 2014, 10:11:30 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plot_field.m
r811 r822 14 14 % function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar) 15 15 % 16 % OU TPUT:16 % OUPUT: 17 17 % PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume' 18 18 % PlotParamOut: structure, representing the updated plotting parameters, in case of automatic scaling 19 19 % haxes: handle of the plotting axis, when a new figure is created. 20 20 % 21 % INPUT:21 %INPUT 22 22 % Data: structure describing the field to plot 23 23 % (optional) .ListGlobalAttribute: cell listing the names of the global attributes … … 81 81 % expressed in figure relative unit (ex [0.821 0.471 0.019 0.445]) 82 82 83 %======================================================================= 84 % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France 85 % http://www.legi.grenoble-inp.fr 86 % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr 87 % 83 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 84 % Copyright 2008-2014, LEGI / CNRS UJF G-INP, Joel.Sommeria@legi.grenoble-inp.fr 85 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 88 86 % This file is part of the toolbox UVMAT. 89 % 87 % 90 88 % UVMAT is free software; you can redistribute it and/or modify 91 % it under the terms of the GNU General Public License as published 92 % by the Free Software Foundation; either version 2 of the license,93 % or(at your option) any later version.94 % 89 % it under the terms of the GNU General Public License as published by 90 % the Free Software Foundation; either version 2 of the License, or 91 % (at your option) any later version. 92 % 95 93 % UVMAT is distributed in the hope that it will be useful, 96 94 % but WITHOUT ANY WARRANTY; without even the implied warranty of 97 95 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 98 % GNU General Public License ( see LICENSE.txt) for more details.99 % =======================================================================96 % GNU General Public License (file UVMAT/COPYING.txt) for more details. 97 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100 98 101 99 function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam) … … 779 777 %% image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%% 780 778 if test_ima 781 782 779 % distinguish B/W and color images 783 780 np=size(A);%size of image … … 798 795 end 799 796 800 %set the color map797 %set for grey scale setting 801 798 if isfield(PlotParam.Scalar,'CheckBW') && ~isempty(PlotParam.Scalar.CheckBW) 802 799 BW=PlotParam.Scalar.CheckBW; %BW=0 color imposed, else gray scale imposed. … … 806 803 end 807 804 808 % determine the plot option 'image' or 'contours' 805 % determine the plot option 'image' or 'contours' 806 CheckContour=0; %default 809 807 if isfield(PlotParam.Scalar,'ListContour') 810 808 CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option 811 else812 CheckContour=0; %default813 809 end 814 810 815 811 %case of grey level images or contour plot 816 if siz==2 817 if ~isfield(PlotParam.Scalar,'CheckFixScalar') 818 PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default 819 end 820 if ~isfield(PlotParam.Scalar,'MinA') 821 PlotParam.Scalar.MinA=[];%no min scalar threshold value set 822 end 823 if ~isfield(PlotParam.Scalar,'MaxA') 824 PlotParam.Scalar.MaxA=[];%no max scalar threshold value set 812 if ~isfield(PlotParam.Scalar,'CheckFixScalar') 813 PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default 814 end 815 if ~isfield(PlotParam.Scalar,'MinA') 816 PlotParam.Scalar.MinA=[];%no min scalar threshold value set 817 end 818 if ~isfield(PlotParam.Scalar,'MaxA') 819 PlotParam.Scalar.MaxA=[];%no max scalar threshold value set 820 end 821 822 % determine the min scalar value 823 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA) 824 MinA=double(PlotParam.Scalar.MinA); % min value set as input 825 else 826 MinA=double(min(min(min(A)))); % min value set as min of non NaN scalar values 827 end 828 829 % error if the input scalar is NaN everywhere 830 if isnan(MinA) 831 errormsg='NaN input scalar or image in plot_field'; 832 return 833 end 834 835 % determine the max scalar value 836 CheckFixScalar=0; 837 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA) 838 MaxA=double(PlotParam.Scalar.MaxA); % max value set as input 839 CheckFixScalar=1; 840 else 841 MaxA=double(max(max(max(A)))); % max value set as min of non NaN scalar values 842 end 843 844 PlotParamOut.Scalar.MinA=MinA; 845 PlotParamOut.Scalar.MaxA=MaxA; 846 PlotParamOut.Scalar.Npx=size(A,2); 847 PlotParamOut.Scalar.Npy=size(A,1); 848 % if siz==2 849 % case of contour plot 850 if CheckContour 851 if ~isempty(hima) && ishandle(hima) 852 delete(hima) % delete existing image 825 853 end 826 854 827 % determine the min scalar value 828 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA) 829 MinA=double(PlotParam.Scalar.MinA); % min value set as input 830 else 831 MinA=double(min(min(A))); % min value set as min of non NaN scalar values 832 end 855 % set the contour values 856 if ~isfield(PlotParam.Scalar,'IncrA') 857 PlotParam.Scalar.IncrA=[];% automatic contour interval 858 end 859 if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA) 860 interval=PlotParam.Scalar.IncrA; 861 else % automatic contour interval 862 cont=colbartick(MinA,MaxA); 863 interval=cont(2)-cont(1);%default 864 PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI 865 end 866 abscontmin=interval*floor(MinA/interval); 867 abscontmax=interval*ceil(MaxA/interval); 868 contmin=interval*floor(min(min(A))/interval); 869 contmax=interval*ceil(max(max(A))/interval); 870 cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines) 871 cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines) 872 cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values 833 873 834 % error if the input scalar is NaN everywhere 835 if isnan(MinA) 836 errormsg='NaN input scalar or image in plot_field'; 837 return 838 end 874 sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1); 875 sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1); 876 x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display 877 y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display 839 878 840 % determine the max scalar value 841 if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA) 842 MaxA=double(PlotParam.Scalar.MaxA); % max value set as input 843 else 844 MaxA=double(max(max(A))); % max value set as min of non NaN scalar values 845 end 879 %axes(haxes)% set the input axes handle as current axis 846 880 847 PlotParamOut.Scalar.MinA=MinA; 848 PlotParamOut.Scalar.MaxA=MaxA; 849 PlotParamOut.Scalar.Npx=size(A,2); 850 PlotParamOut.Scalar.Npy=size(A,1); 881 % colormap(map); 882 tag_axes=get(haxes,'Tag');% axes tag 883 Opacity=1; 884 if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity) 885 Opacity=PlotParam.Scalar.Opacity; 886 end 887 % fill the space between contours if opacity is undefined or =1 888 if isequal(Opacity,1) 889 [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours 890 set(hcontour,'Fill','on')% fill the space between contours 891 set(hcontour,'LineStyle','none') 892 hold on 893 end 894 [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines 895 hold on 896 [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines 897 if isequal(Opacity,1) 898 set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background) 899 end 900 set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !) 901 hold off 851 902 852 % case of contour plot 853 if CheckContour 854 if ~isempty(hima) && ishandle(hima) 855 delete(hima) % delete existing image 856 end 857 858 % set the contour values 859 if ~isfield(PlotParam.Scalar,'IncrA') 860 PlotParam.Scalar.IncrA=[];% automatic contour interval 861 end 862 if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA) 863 interval=PlotParam.Scalar.IncrA; 864 else % automatic contour interval 865 cont=colbartick(MinA,MaxA); 866 interval=cont(2)-cont(1);%default 867 PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI 868 end 869 %B=A; 870 abscontmin=interval*floor(MinA/interval); 871 abscontmax=interval*ceil(MaxA/interval); 872 contmin=interval*floor(min(min(A))/interval); 873 contmax=interval*ceil(max(max(A))/interval); 874 cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines) 875 cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines) 876 cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values 877 878 sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1); 879 sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1); 880 x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display 881 y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display 882 883 %axes(haxes)% set the input axes handle as current axis 884 885 % colormap(map); 886 tag_axes=get(haxes,'Tag');% axes tag 887 Opacity=1; 888 if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity) 889 Opacity=PlotParam.Scalar.Opacity; 890 end 891 % fill the space between contours if opacity is undefined or =1 892 if isequal(Opacity,1) 893 [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours 894 set(hcontour,'Fill','on')% fill the space between contours 895 set(hcontour,'LineStyle','none') 896 hold on 897 end 898 [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines 899 hold on 900 [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines 901 if isequal(Opacity,1) 902 set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background) 903 end 904 set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !) 905 hold off 906 907 %determine the color scale and map 908 caxis([abscontmin abscontmax]) 909 if BW 910 vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval 911 map=[vec' vec' vec']; 912 colormap(map); 903 %determine the color scale and map 904 caxis([abscontmin abscontmax]) 905 if BW 906 vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval 907 map=[vec' vec' vec']; 908 colormap(map); 909 else 910 colormap('default'); % default matlab colormap ('jet') 911 end 912 913 if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1) 914 set(haxes,'DataAspectRatioMode','manual') 915 if isfield(PlotParam.Axes,'AspectRatio') 916 set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1]) 913 917 else 914 colormap('default'); % default matlab colormap ('jet') 915 end 916 917 if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1) 918 set(haxes,'DataAspectRatioMode','manual') 919 if isfield(PlotParam.Axes,'AspectRatio') 920 set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1]) 921 else 922 set(haxes,'DataAspectRatio',[1 1 1]) 923 end 924 end 925 else 918 set(haxes,'DataAspectRatio',[1 1 1]) 919 end 920 end 921 else %usual images (no contour) 926 922 % set colormap for image display 927 % rescale the grey levels with min and max, put a grey scale colorbar 928 % B=A; 929 if BW 930 vec=linspace(0,1,255);%define a linear greyscale colormap 931 map=[vec' vec' vec']; 932 colormap(map); %grey scale color map 933 else 934 colormap('default'); % standard false colors for div, vort , scalar fields 935 end 923 if BW 924 vec=linspace(0,1,255);%define a linear greyscale colormap 925 map=[vec' vec' vec']; 926 colormap(map); %grey scale color map 927 if siz==3% true color images visualized in BW 928 A=uint16(sum(A,3));%sum the three color components for color images displayed with BW option 929 end 930 else 931 if siz==3 && CheckFixScalar % true color images rescaled by MaxA 932 A=uint8(255*double(A)/double(MaxA)); 933 end 934 colormap('default'); % standard false colors for div, vort , scalar fields 936 935 end 937 936 938 % case of color images939 else940 if BW941 A=uint16(sum(A,3));942 else943 A=uint8(A);944 end945 MinA=0;946 MaxA=255;947 end948 949 % display usual image950 if ~CheckContour951 937 % interpolate field to increase resolution of image display 952 938 test_interp=0; 953 if size(A,3)==1 % scalar o fB/W image939 if size(A,3)==1 % scalar or B/W image 954 940 test_interp=1; 955 941 if max(np) <= 64 … … 1014 1000 %display the colorbar code for B/W images if Poscolorbar not empty 1015 1001 if ~isempty(PosColorbar) 1016 if siz ==2&& exist('PosColorbar','var')1002 if size(A,3)==1 && exist('PosColorbar','var') 1017 1003 if isempty(hcol)||~ishandle(hcol) 1018 1004 hcol=colorbar;%create new colorbar
Note: See TracChangeset
for help on using the changeset viewer.