Home > atmlab > math > taylor_diagram.m

taylor_diagram

PURPOSE ^

% taylor_diagram (creates Taylor diagram)

SYNOPSIS ^

function varargout = taylor_diagram(STDs,RMSs,CORs,opt)

DESCRIPTION ^

% taylor_diagram (creates Taylor diagram)


 REFERENCE TO:     K. Taylor , Summarizing multiple aspects of model
                   performance in a single diagram Journal of Geophysical
                   Research-Atmospheres, 2001, V106, D7. 


 [hp ht axl] = taylordiag(STDs,RMSs,CORs,['option',value])

 Plot a Taylor diagram from statistics values given
 by STDs (standard deviations), RMSs (centered root mean
 square difference) and CORs (correlation)

 Each of STDs, RMS and CORs are one dimensional tables
 with N variables. The 1st value corresponds to the observation
 statistics to compair with the others.

 OUTPUTS:
     hp: returns a handle to the plotted points
    ht: returns a handle to the text legend of points
  axl: returns a structure of handles of axis labels

 LIST OF OPTIONS:

 'Npan'
        1 or 2: Panels to display (1 for positive correlations,
                2 for positive and negative correlations)
                Default value depends on CORs

 'tickRMS'
         RMS values to plot gridding circles from observation point
 'colRMS'
        RMS grid and tick labels color
        Default: green
 'showlabelsRMS'
        0 / 1 (default): Show or not the RMS tick labels
 'tickRMSangle'
        Angle for RMS tick lables with the observation point
        Default: 135 deg.
 'styleRMS'
        Linestyle of the RMS grid
 'widthRMS'
        Line width of the RMS grid
 'titleRMS'
        0 / 1 (default): Show RMSD axis title

 'tickSTD'
        STD values to plot gridding circles from origin
 'colSTD'
        STD grid and tick labels color
        Default: black
 'showlabelsSTD'
        0 / 1 (default): Show or not the STD tick labels
 'styleSTD'
        Linestyle of the STD grid
 'widthSTD'
        Line width of the STD grid
 'titleSTD'
        0 / 1 (default): Show STD axis title

 'tickCOR'
        CORRELATON grid values
 'colCOR'
        CORRELATION grid color
        Default: blue
 'showlabelsCOR'
        0 / 1 (default): Show or not the CORRELATION tick labels
 'styleCOR'
        Linestyle of the COR grid
 'widthCOR'
        Line width of the COR grid
 'titleCOR'
        0 / 1 (default): Show CORRELATION axis title


 Created: G. Maze (07/02/2008)
%%%
Extra options (added by Salomon)
 'pointnames' {%s,%s,...}    Names associated with points to be plotted
                             alongside the points. Default = {'A','B',...}

 'pointcolor' {%s,%s,} or {[%f rgb],[%f rgb],}
                             Color of the individual points. Can be given
                             as vector
                        
 'pointsymbols' ['.','s',..] Symbol associated with point

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

taylor_diagram.m

SOURCE CODE ^

0001 function varargout = taylor_diagram(STDs,RMSs,CORs,opt)
0002 %% taylor_diagram (creates Taylor diagram)
0003 %
0004 %
0005 % REFERENCE TO:     K. Taylor , Summarizing multiple aspects of model
0006 %                   performance in a single diagram Journal of Geophysical
0007 %                   Research-Atmospheres, 2001, V106, D7.
0008 %
0009 %
0010 % [hp ht axl] = taylordiag(STDs,RMSs,CORs,['option',value])
0011 %
0012 % Plot a Taylor diagram from statistics values given
0013 % by STDs (standard deviations), RMSs (centered root mean
0014 % square difference) and CORs (correlation)
0015 %
0016 % Each of STDs, RMS and CORs are one dimensional tables
0017 % with N variables. The 1st value corresponds to the observation
0018 % statistics to compair with the others.
0019 %
0020 % OUTPUTS:
0021 %     hp: returns a handle to the plotted points
0022 %    ht: returns a handle to the text legend of points
0023 %  axl: returns a structure of handles of axis labels
0024 %
0025 % LIST OF OPTIONS:
0026 %
0027 % 'Npan'
0028 %        1 or 2: Panels to display (1 for positive correlations,
0029 %                2 for positive and negative correlations)
0030 %                Default value depends on CORs
0031 %
0032 % 'tickRMS'
0033 %         RMS values to plot gridding circles from observation point
0034 % 'colRMS'
0035 %        RMS grid and tick labels color
0036 %        Default: green
0037 % 'showlabelsRMS'
0038 %        0 / 1 (default): Show or not the RMS tick labels
0039 % 'tickRMSangle'
0040 %        Angle for RMS tick lables with the observation point
0041 %        Default: 135 deg.
0042 % 'styleRMS'
0043 %        Linestyle of the RMS grid
0044 % 'widthRMS'
0045 %        Line width of the RMS grid
0046 % 'titleRMS'
0047 %        0 / 1 (default): Show RMSD axis title
0048 %
0049 % 'tickSTD'
0050 %        STD values to plot gridding circles from origin
0051 % 'colSTD'
0052 %        STD grid and tick labels color
0053 %        Default: black
0054 % 'showlabelsSTD'
0055 %        0 / 1 (default): Show or not the STD tick labels
0056 % 'styleSTD'
0057 %        Linestyle of the STD grid
0058 % 'widthSTD'
0059 %        Line width of the STD grid
0060 % 'titleSTD'
0061 %        0 / 1 (default): Show STD axis title
0062 %
0063 % 'tickCOR'
0064 %        CORRELATON grid values
0065 % 'colCOR'
0066 %        CORRELATION grid color
0067 %        Default: blue
0068 % 'showlabelsCOR'
0069 %        0 / 1 (default): Show or not the CORRELATION tick labels
0070 % 'styleCOR'
0071 %        Linestyle of the COR grid
0072 % 'widthCOR'
0073 %        Line width of the COR grid
0074 % 'titleCOR'
0075 %        0 / 1 (default): Show CORRELATION axis title
0076 %
0077 %
0078 % Created: G. Maze (07/02/2008)
0079 %%%%
0080 %Extra options (added by Salomon)
0081 % 'pointnames' {%s,%s,...}    Names associated with points to be plotted
0082 %                             alongside the points. Default = {'A','B',...}
0083 %
0084 % 'pointcolor' {%s,%s,} or {[%f rgb],[%f rgb],}
0085 %                             Color of the individual points. Can be given
0086 %                             as vector
0087 %
0088 % 'pointsymbols' ['.','s',..] Symbol associated with point
0089 %
0090 % $Id$
0091 
0092 %% CHECK THE INPUT FIELDS TO BE SURE WE HAVE:
0093 % rms^2 = st.^2 + st(end)^2 - 2*st*st(end).*co
0094 apro = 100;
0095 di = fix(RMSs*apro)/apro - fix(sqrt(STDs.^2 + STDs(1)^2 - 2*STDs*STDs(1).*CORs)*apro)/apro;
0096 assert(all(di==0),'atmlab:taylor_diagram:badInput',['Something''s wrong with the datas\n'...
0097     'We must have:\n','RMSs - sqrt(STDs.^2 + STDs(1)^2 - 2*STDs*STDs(1).*CORs) = 0 !'])
0098 assert(nargin>=3,'atmlab:taylor_diagram:badInput','USAGE: taylor_diagram(STDs,RMSs,CORs,opt)')
0099 if nargin ==3, opt = struct; end
0100 
0101 %% IN POLAR COORDINATES:
0102 if isfield(opt,'normalize')&&opt.normalize
0103     STDs = STDs./STDs(1);
0104 end
0105 rho   = STDs;
0106 theta = acos(CORs);
0107 dx = rho(1);    % Observed STD
0108 
0109 %% BEGIN THE PLOT HERE TO GET AXIS VALUES:
0110 hold off
0111 cax = gca;
0112 tc = get(cax,'xcolor');
0113 next = lower(get(cax,'NextPlot'));
0114 
0115 % make a radial grid
0116 hold(cax,'on');
0117 maxrho = max(abs(rho(:)));
0118 hhh=line([-maxrho -maxrho maxrho maxrho],[-maxrho maxrho maxrho -maxrho],'parent',cax);
0119 xlim([0 maxrho])
0120 ylim([0 maxrho])
0121 set(cax,'dataaspectratio',[1 1 1],'plotboxaspectratiomode','auto')
0122 % Salomons
0123 %v = [get(cax,'xlim') get(cax,'ylim')];
0124 a = get(cax,'xtick');b = get(cax,'ytick');
0125 v = [a(1) a(end)+a(2) b(1) b(end)+b(2)];
0126 
0127 %% cont..
0128 ticks = sum(get(cax,'ytick')>=0);
0129 delete(hhh);
0130 
0131 % check radial limits and ticks
0132 rmin = 0;
0133 rmax = v(4);
0134 rticks = max(ticks-1,2);
0135 if rticks > 5   % see if we can reduce the number
0136     if rem(rticks,2) == 0
0137         rticks = rticks/2;
0138     elseif rem(rticks,3) == 0
0139         rticks = rticks/3;
0140     end
0141 end
0142 rinc  = (rmax-rmin)/rticks;
0143 tick  = (rmin+rinc):rinc:rmax;
0144 
0145 %% LOAD DEFAULT PARAMETERS:
0146 default.Npan = 1+any(CORs<0); %double panel?
0147 default.tickRMSangle  = 135;
0148 default.showlabelsRMS = true;
0149 default.showlabelsSTD = true;
0150 default.tickRMS = tick;
0151 default.rincRMS = rinc;
0152 default.tickSTD = tick;
0153 default.colSTD = [0 0 0];
0154 default.colRMS = [0 .6 0];
0155 default.colCOR = [0 0 1];
0156 default.tickCOR(1).val = [1 .99 .95 .9:-.1:0];
0157 default.tickCOR(2).val = [1 .99 .95 .9:-.1:0 -.1:-.1:-.9 -.95 -.99 -1];
0158 default.widthSTD = .8;
0159 default.widthRMS = .8;
0160 default.widthCOR = .8;
0161 default.styleSTD = ':';
0162 default.styleRMS = '--';
0163 default.styleCOR = '-.';
0164 default.titleSTD = true;
0165 default.titleRMS = true;
0166 default.titleCOR = true;
0167 
0168 % Salomon's added options
0169 default.pointnames    ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',...
0170     'P','Q','R','S','T','U','V','W','X','Y','Z'};
0171 default.pointcolor    = repmat({[1 0 0]},length(STDs),1);
0172 default.pointsymbols  = repmat('.',1,length(STDs));
0173 
0174 opt = optargs_struct(default,opt);
0175 
0176 %% CONTINUE THE PLOT WITH UPDATED OPTIONS:
0177 
0178 % define a circle
0179 th = 0:pi/150:2*pi;
0180 xunit = cos(th);
0181 yunit = sin(th);
0182 % now really force points on x/y axes to lie on them exactly
0183 inds = 1:(length(th)-1)/4:length(th);
0184 xunit(inds(2:2:4)) = zeros(2,1);
0185 yunit(inds(1:2:5)) = zeros(3,1);
0186 % plot background if necessary
0187 if ~ischar(get(cax,'color')),
0188     %        ig = find(th>=0 & th<=pi);
0189     ig = 1:length(th);
0190     patch('xdata',xunit(ig)*rmax,'ydata',yunit(ig)*rmax, ...
0191         'edgecolor',tc,'facecolor',get(cax,'color'),...
0192         'handlevisibility','off','parent',cax);
0193 end
0194 
0195 % DRAW RMS CIRCLES:
0196 % ANGLE OF THE TICK LABELS
0197 c82 = cos(opt.tickRMSangle*pi/180);
0198 s82 = sin(opt.tickRMSangle*pi/180);
0199 for ic = 1 : length(opt.tickRMS)
0200     i = opt.tickRMS(ic);
0201     iphic = find( sqrt(dx^2+rmax^2-2*dx*rmax*xunit) >= i ,1);
0202     ig = find(i*cos(th)+dx <= rmax*cos(th(iphic)));
0203     hhh = line(xunit(ig)*i+dx,yunit(ig)*i,'linestyle',opt.styleRMS,'color',opt.colRMS,'linewidth',opt.widthRMS,...
0204         'handlevisibility','off','parent',cax);
0205     if opt.showlabelsRMS
0206         text((i+opt.rincRMS/20)*c82+dx,(i+opt.rincRMS/20)*s82, ...
0207             ['  ' num2str(i)],'verticalalignment','bottom',...
0208             'handlevisibility','off','parent',cax,'color',opt.colRMS,'rotation',opt.tickRMSangle-90)
0209     end
0210 end
0211 
0212 % DRAW DIFFERENTLY THE CIRCLE CORRESPONDING TO THE OBSERVED VALUE
0213 %      hhh = line((cos(th)*dx),sin(th)*dx,'linestyle','--','color',opt.colSTD,'linewidth',1,...
0214 %                   'handlevisibility','off','parent',cax);
0215 
0216 
0217 % DRAW STD CIRCLES:
0218 % draw radial circles
0219 for ic = 1 : length(opt.tickSTD)
0220     i = opt.tickSTD(ic);
0221     hhh = line(xunit*i,yunit*i,'linestyle',opt.styleSTD,'color',opt.colSTD,'linewidth',opt.widthSTD,...
0222         'handlevisibility','off','parent',cax);
0223     if opt.showlabelsSTD
0224         if opt.Npan == 2
0225             if isempty(find(opt.tickSTD==0, 1))
0226                 text(0,-rinc/20,'0','verticalalignment','top','horizontalAlignment','center',...
0227                     'handlevisibility','off','parent',cax,'color',opt.colSTD);
0228             end
0229             text(i,-rinc/20, ...
0230                 num2str(i),'verticalalignment','top','horizontalAlignment','center',...
0231                 'handlevisibility','off','parent',cax,'color',opt.colSTD)
0232         else
0233             if isempty(find(opt.tickSTD==0, 1))
0234                 text(-rinc/20,rinc/20,'0','verticalalignment','middle','horizontalAlignment','right',...
0235                     'handlevisibility','off','parent',cax,'color',opt.colSTD);
0236             end
0237             text(-rinc/20,i, ...
0238                 num2str(i),'verticalalignment','middle','horizontalAlignment','right',...
0239                 'handlevisibility','off','parent',cax,'color',opt.colSTD)
0240         end
0241     end
0242 end
0243 set(hhh,'linestyle','-') % Make outer circle solid
0244 
0245 % DRAW CORRELATIONS LINES EMANATING FROM THE ORIGIN:
0246 corr = opt.tickCOR(opt.Npan).val;
0247 th  = acos(corr);
0248 cst = cos(th); snt = sin(th);
0249 cs = [-cst; cst];
0250 sn = [-snt; snt];
0251 line(rmax*cs,rmax*sn,'linestyle',opt.styleCOR,'color',opt.colCOR,'linewidth',opt.widthCOR,...
0252     'handlevisibility','off','parent',cax)
0253 
0254 % annotate them in correlation coef
0255 rt = 1.05*rmax;
0256 parfor i = 1:length(corr)
0257     text(rt*cst(i),rt*snt(i),num2str(corr(i)),...
0258         'horizontalalignment','center',...
0259         'handlevisibility','off','parent',cax,'color',opt.colCOR);
0260 %     if i == length(corr)
0261 %         loc = int2str(0);
0262 %         loc = '1';
0263 %     else
0264 %         loc = int2str(180+i*30);
0265 %         loc = '-1';
0266 %     end
0267 end
0268 
0269 % AXIS TITLES
0270 axlabweight = 'bold';
0271 ix = 0;
0272 if opt.Npan == 1
0273     if opt.titleSTD
0274         ix = ix + 1;
0275         ax(ix).handle = ylabel('Standard deviation','color',opt.colSTD,'fontweight',axlabweight);
0276     end
0277     
0278     if opt.titleCOR
0279         ix = ix + 1;
0280         clear ttt
0281         pos1 = 45;    DA = 15;
0282         lab = 'Correlation Coefficient';
0283         c = fliplr(linspace(pos1-DA,pos1+DA,length(lab)));
0284         dd = 1.1*rmax;    ii = 0;
0285         for ic = 1 : length(c)
0286             ith = c(ic);
0287             ii = ii + 1;
0288             ttt(ii)=text(dd*cos(ith*pi/180),dd*sin(ith*pi/180),lab(ii));
0289             set(ttt(ii),'rotation',ith-90,'color',opt.colCOR,'horizontalalignment','center',...
0290                 'verticalalignment','bottom','fontsize',get(ax(1).handle,'fontsize'),'fontweight',axlabweight);
0291         end
0292         ax(ix).handle = ttt;
0293     end
0294     
0295     if opt.titleRMS
0296         ix = ix + 1;
0297         clear ttt
0298         pos1 = opt.tickRMSangle+(180-opt.tickRMSangle)/2; DA = 15; pos1 = 160;
0299         lab = 'RMSD';
0300         c = fliplr(linspace(pos1-DA,pos1+DA,length(lab)));
0301         dd = 1.05*opt.tickRMS(1);
0302         dd = .95*opt.tickRMS(2);
0303         ii = 0;
0304         for ic = 1 : length(c)
0305             ith = c(ic);
0306             ii = ii + 1;
0307             ttt(ii)=text(dx+dd*cos(ith*pi/180),dd*sin(ith*pi/180),lab(ii));
0308             set(ttt(ii),'rotation',ith-90,'color',opt.colRMS,'horizontalalignment','center',...
0309                 'verticalalignment','top','fontsize',get(ax(1).handle,'fontsize'),'fontweight',axlabweight);
0310         end
0311         ax(ix).handle = ttt;
0312     end
0313     
0314     
0315 else
0316     if opt.titleSTD
0317         ix = ix + 1;
0318         ax(ix).handle =xlabel('Standard deviation','fontweight',axlabweight,'color',opt.colSTD);
0319     end
0320     
0321     if opt.titleCOR
0322         ix = ix + 1;
0323         clear ttt
0324         pos1 = 90;    DA = 15;
0325         lab = 'Correlation Coefficient';
0326         c = fliplr(linspace(pos1-DA,pos1+DA,length(lab)));
0327         dd = 1.1*rmax;    ii = 0;
0328         for ic = 1 : length(c)
0329             ith = c(ic);
0330             ii = ii + 1;
0331             ttt(ii)=text(dd*cos(ith*pi/180),dd*sin(ith*pi/180),lab(ii));
0332             set(ttt(ii),'rotation',ith-90,'color',opt.colCOR,'horizontalalignment','center',...
0333                 'verticalalignment','bottom','fontsize',get(ax(1).handle,'fontsize'),'fontweight',axlabweight);
0334         end
0335         ax(ix).handle = ttt;
0336     end
0337     
0338     if opt.titleRMS
0339         ix = ix + 1;
0340         clear ttt
0341         pos1 = 160; DA = 10;
0342         lab = 'RMSD';
0343         c = fliplr(linspace(pos1-DA,pos1+DA,length(lab)));
0344         dd = 1.05*opt.tickRMS(1); ii = 0;
0345         for ic = 1 : length(c)
0346             ith = c(ic);
0347             ii = ii + 1;
0348             ttt(ii)=text(dx+dd*cos(ith*pi/180),dd*sin(ith*pi/180),lab(ii));
0349             set(ttt(ii),'rotation',ith-90,'color',opt.colRMS,'horizontalalignment','center',...
0350                 'verticalalignment','bottom','fontsize',get(ax(1).handle,'fontsize'),'fontweight',axlabweight);
0351         end
0352         ax(ix).handle = ttt;
0353     end
0354 end
0355 
0356 
0357 % VARIOUS ADJUSTMENTS TO THE PLOT:
0358 set(cax,'dataaspectratio',[1 1 1]), axis(cax,'off'); set(cax,'NextPlot',next);
0359 set(get(cax,'xlabel'),'visible','on')
0360 set(get(cax,'ylabel'),'visible','on')
0361 %    makemcode('RegisterHandle',cax,'IgnoreHandle',q,'FunctionName','polar');
0362 % set view to 2-D
0363 view(cax,2);
0364 % set axis limits
0365 if opt.Npan == 2
0366     axis(cax,rmax*[-1.15 1.15 0 1.15]);
0367     line([-rmax rmax],[0 0],'color',tc,'linewidth',1.2);
0368     line([0 0],[0 rmax],'color',tc);
0369 else
0370     axis(cax,rmax*[0 1.15 0 1.15]);
0371     %        axis(cax,rmax*[-1 1 -1.15 1.15]);
0372     line([0 rmax],[0 0],'color',tc,'linewidth',1.2);
0373     line([0 0],[0 rmax],'color',tc,'linewidth',2);
0374 end
0375 
0376 
0377 % FINALY PLOT THE POINTS:
0378 hold on
0379 pp=zeros(length(STDs),1);
0380 for ii = 1 : length(STDs)
0381     pp(ii)=polar(theta(ii),rho(ii));
0382     if strcmp(opt.pointsymbols(ii),'s')
0383         set(pp(ii),'marker',opt.pointsymbols(ii),'MarkerEdgeColor',opt.pointcolor{ii},'MarkerFaceColor',opt.pointcolor{ii},'markersize',10);
0384     else
0385         set(pp(ii),'marker',opt.pointsymbols(ii),'markersize',40);
0386     end
0387     set(pp(ii),'color',opt.pointcolor{ii});
0388     if length(STDs)<=26
0389         tt(ii)=text(rho(ii)*cos(theta(ii)),rho(ii)*sin(theta(ii)),opt.pointnames{ii},'color',opt.pointcolor{ii});
0390     else
0391         tt(ii)=text(rho(ii)*cos(theta(ii)),rho(ii)*sin(theta(ii)),lower(opt.pointnames{ii}),'color',opt.pointcolor{ii});
0392     end
0393 end
0394 set(tt,'verticalalignment','bottom','horizontalalignment','right')
0395 set(tt,'fontsize',12)
0396 hold off
0397 
0398 %%% OUTPUT
0399 switch nargout
0400     case 1
0401         varargout(1) = {pp};
0402     case 2
0403         varargout(1) = {pp};
0404         varargout(2) = {tt};
0405     case 3
0406         varargout(1) = {pp};
0407         varargout(2) = {tt};
0408         varargout(3) = {ax};
0409 end
0410 
0411 
0412 
0413 
0414 
0415 
0416 
0417

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005