Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

circ_plot.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. function a = circ_plot(alpha, format, formats, varargin)
  2. %
  3. % r = circ_plot(alpha, ...)
  4. % Plotting routines for circular data.
  5. %
  6. % Input:
  7. % alpha sample of angles in radians
  8. % [format specifies style of plot
  9. % pretty, histogram, density, []
  10. % [formats standard matlab string for plot format (like '.r')]
  11. %
  12. % The different plotting styles take optional arguments:
  13. % pretty: fourth argument toggles between showing mean direction
  14. % and not showing it
  15. % hist: fourth argument determines number of bins/bin centers
  16. % fifth argument determines whether normalized or count
  17. % histogram is shown
  18. % sixth argument toggles between showing mean direction
  19. % and not showing it
  20. %
  21. % All of these arguments can be left empty, i.e. set to [], so that
  22. % the default value will be used. If additional arguments are
  23. % supplied in the name-value style ('linewidth', 2, ...), these are
  24. % used to change the properties of the mean resultant vector plot.
  25. %
  26. % Output:
  27. % a axis handle
  28. %
  29. % Examples:
  30. % alpha = randn(60,1)*.4+pi/2;
  31. % figure
  32. % subplot(2,2,1)
  33. % circ_plot(alpha,'pretty','ro',true,'linewidth',2,'color','r'),
  34. % title('pretty plot style')
  35. % subplot(2,2,2)
  36. % circ_plot(alpha,'hist',[],20,true,true,'linewidth',2,'color','r')
  37. % title('hist plot style')
  38. % subplot(2,2,3)
  39. % circ_plot(alpha,[],'s')
  40. % title('non-fancy plot style')
  41. %
  42. %
  43. % Circular Statistics Toolbox for Matlab
  44. % By Philipp Berens & Marc J. Velasco, 2009
  45. % velasco@ccs.fau.edu, berens@tuebingen.mpg.de
  46. if nargin < 2 || isempty(format)
  47. format = '';
  48. end
  49. switch format
  50. case 'pretty'
  51. % plot in 'pretty style'
  52. % draws unit circle and marks points around the circle
  53. % adds optionally the mean resultant vector
  54. if nargin < 3|| isempty(formats)
  55. formats = 'o';
  56. end
  57. % convert angles to unit vectors
  58. z = exp(i*alpha);
  59. % create unit circle
  60. zz = exp(i*linspace(0, 2*pi, 101));
  61. plot(real(z), imag(z), formats, real(zz), imag(zz), 'k', [-2 2], [0 0], 'k:', [0 0], [-2 2], 'k:');
  62. set(gca, 'XLim', [-1.1 1.1], 'YLim', [-1.1 1.1])
  63. % plot mean directions with an overlaid arrow if desired
  64. if nargin > 2 && ~isempty(varargin{1})
  65. s = varargin{1};
  66. else
  67. s = true;
  68. end
  69. if s
  70. r = circ_r(alpha);
  71. phi = circ_mean(alpha);
  72. hold on;
  73. zm = r*exp(i*phi);
  74. plot([0 real(zm)], [0, imag(zm)],varargin{2:end})
  75. hold off;
  76. end
  77. axis square;
  78. set(gca,'box','off')
  79. set(gca,'xtick',[])
  80. set(gca,'ytick',[])
  81. text(1.2, 0, '0'); text(-.05, 1.2, '\pi/2'); text(-1.35, 0, '±\pi'); text(-.075, -1.2, '-\pi/2');
  82. case 'hist'
  83. % plot in 'hist style'
  84. % this is essentially a wrapper for the rose plot function of matlab
  85. % adds optionally the mean resultant vector
  86. if nargin < 3|| isempty(formats)
  87. formats = '-';
  88. end
  89. if nargin > 3 && ~isempty(varargin{1})
  90. x = varargin{1};
  91. else
  92. x = 20;
  93. end
  94. [t,r] = rose(alpha,x);
  95. if nargin> 3 && varargin{2}
  96. polar(t,r/sum(r),formats)
  97. mr = max(r/sum(r));
  98. else
  99. polar(t,r,formats)
  100. mr = max(r);
  101. end
  102. % plot mean directions with an overlaid arrow if desired
  103. if nargin > 5 && ~isempty(varargin{3})
  104. s = varargin{1};
  105. else
  106. s = true;
  107. end
  108. if s
  109. r = circ_r(alpha) * mr;
  110. phi = circ_mean(alpha);
  111. hold on;
  112. zm = r*exp(i*phi);
  113. plot([0 real(zm)], [0, imag(zm)],varargin{4:end})
  114. hold off;
  115. end
  116. otherwise
  117. if nargin < 3
  118. formats = 'o';
  119. end
  120. polar(alpha, ones(size(alpha)), formats);
  121. end
  122. a = gca;