Home > atmlab > circular > circ_plot.m

circ_plot

PURPOSE ^

SYNOPSIS ^

function a = circ_plot(alpha, format, formats, varargin)

DESCRIPTION ^

 r = circ_plot(alpha, ...)
   Plotting routines for circular data.

   Input:
     alpha     sample of angles in radians
     [format        specifies style of plot
                 pretty, histogram, density, []
     [formats  standard matlab string for plot format (like '.r')]

     The different plotting styles take optional arguments:
         pretty:   fourth argument toggles between showing mean direction
                     and not showing it
         hist:     fourth argument determines number of bins/bin centers
                   fifth argument determines whether normalized or count
                     histogram is shown
                   sixth argument toggles between showing mean direction
                     and not showing it

       All of these arguments can be left empty, i.e. set to [], so that
       the default value will be used. If additional arguments are
       supplied in the name-value style ('linewidth', 2, ...), these are
       used to change the properties of the mean resultant vector plot.         

   Output:
     a         axis handle

   Examples:
     alpha = randn(60,1)*.4+pi/2;
     figure
     subplot(2,2,1)
     circ_plot(alpha,'pretty','ro',true,'linewidth',2,'color','r'),
     title('pretty plot style')
     subplot(2,2,2)
     circ_plot(alpha,'hist',[],20,true,true,'linewidth',2,'color','r')
     title('hist plot style')
     subplot(2,2,3)
     circ_plot(alpha,[],'s')
     title('non-fancy plot style')
    

 Circular Statistics Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

circ_plot.m

SOURCE CODE ^

0001 function a = circ_plot(alpha, format, formats, varargin)
0002 %
0003 % r = circ_plot(alpha, ...)
0004 %   Plotting routines for circular data.
0005 %
0006 %   Input:
0007 %     alpha     sample of angles in radians
0008 %     [format        specifies style of plot
0009 %                 pretty, histogram, density, []
0010 %     [formats  standard matlab string for plot format (like '.r')]
0011 %
0012 %     The different plotting styles take optional arguments:
0013 %         pretty:   fourth argument toggles between showing mean direction
0014 %                     and not showing it
0015 %         hist:     fourth argument determines number of bins/bin centers
0016 %                   fifth argument determines whether normalized or count
0017 %                     histogram is shown
0018 %                   sixth argument toggles between showing mean direction
0019 %                     and not showing it
0020 %
0021 %       All of these arguments can be left empty, i.e. set to [], so that
0022 %       the default value will be used. If additional arguments are
0023 %       supplied in the name-value style ('linewidth', 2, ...), these are
0024 %       used to change the properties of the mean resultant vector plot.
0025 %
0026 %   Output:
0027 %     a         axis handle
0028 %
0029 %   Examples:
0030 %     alpha = randn(60,1)*.4+pi/2;
0031 %     figure
0032 %     subplot(2,2,1)
0033 %     circ_plot(alpha,'pretty','ro',true,'linewidth',2,'color','r'),
0034 %     title('pretty plot style')
0035 %     subplot(2,2,2)
0036 %     circ_plot(alpha,'hist',[],20,true,true,'linewidth',2,'color','r')
0037 %     title('hist plot style')
0038 %     subplot(2,2,3)
0039 %     circ_plot(alpha,[],'s')
0040 %     title('non-fancy plot style')
0041 %
0042 %
0043 % Circular Statistics Toolbox for Matlab
0044 
0045 % By Philipp Berens & Marc J. Velasco, 2009
0046 % velasco@ccs.fau.edu, berens@tuebingen.mpg.de
0047 
0048 if nargin < 2 || isempty(format)
0049     format = '';
0050 end
0051 
0052 
0053 switch format
0054   case 'pretty'
0055     % plot in 'pretty style'
0056     % draws unit circle and marks points around the circle
0057     % adds optionally the mean resultant vector
0058     
0059     if nargin < 3|| isempty(formats) 
0060       formats = 'o';
0061     end
0062     
0063     % convert angles to unit vectors
0064     z = exp(i*alpha);
0065 
0066     % create unit circle
0067     zz = exp(i*linspace(0, 2*pi, 101));
0068 
0069     plot(real(z), imag(z), formats, real(zz), imag(zz), 'k', [-2 2], [0 0], 'k:', [0 0], [-2 2], 'k:');
0070     set(gca, 'XLim', [-1.1 1.1], 'YLim', [-1.1 1.1])
0071 
0072     % plot mean directions with an overlaid arrow if desired
0073     if nargin > 2 && ~isempty(varargin{1})
0074       s = varargin{1};
0075     else
0076       s = true;
0077     end
0078     
0079     if s
0080       r = circ_r(alpha);
0081       phi = circ_mean(alpha);
0082       hold on;
0083       zm = r*exp(i*phi);
0084       plot([0 real(zm)], [0, imag(zm)],varargin{2:end})
0085       hold off;
0086     end
0087 
0088     axis square;
0089     set(gca,'box','off')
0090     set(gca,'xtick',[])
0091     set(gca,'ytick',[])
0092     text(1.2, 0, '0'); text(-.05, 1.2, '\pi/2');  text(-1.35, 0, '�\pi');  text(-.075, -1.2, '-\pi/2');
0093 
0094     
0095   case 'hist'
0096     % plot in  'hist style'
0097     % this is essentially a wrapper for the rose plot function of matlab
0098     % adds optionally the mean resultant vector
0099     
0100     if nargin < 3|| isempty(formats) 
0101       formats = '-';
0102     end
0103     
0104     if nargin > 3 && ~isempty(varargin{1})
0105       x = varargin{1};
0106     else
0107       x = 20;
0108     end
0109     
0110     [t,r] = rose(alpha,x);
0111     if nargin> 3 && varargin{2}
0112       polar(t,r/sum(r),formats)
0113       mr = max(r/sum(r));
0114     else
0115       polar(t,r,formats)
0116       mr = max(r);
0117     end
0118     
0119      % plot mean directions with an overlaid arrow if desired
0120     if nargin > 5 && ~isempty(varargin{3})
0121       s = varargin{1};
0122     else
0123       s = true;
0124     end
0125     
0126     if s
0127       r = circ_r(alpha) * mr;
0128       phi = circ_mean(alpha);
0129       hold on;
0130       zm = r*exp(i*phi);
0131       plot([0 real(zm)], [0, imag(zm)],varargin{4:end})
0132       hold off;
0133     end
0134     
0135    
0136   otherwise
0137     if nargin < 3
0138       formats = 'o';
0139     end
0140     polar(alpha, ones(size(alpha)), formats);
0141 end
0142 
0143 a = gca;

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