使用polarhistogram(theta)
绘制包含0-360度方位角的数据集时。是否可以为给定的段指定颜色?
例如,在下图中,是否可以指定0到90度之间的所有条形(因此也是180-270度)都是红色的?其余的仍然是蓝色的?
我认为如果它存在,它会在这里的某个地方,但我无法弄清楚究竟是哪一部分:
https://www.mathworks.com/help/matlab/ref/polaraxes-properties.html
答案 0 :(得分:1)
如果使用rose
,则可以提取直方图的边缘并逐个绘制每个条形图。这有点像黑客但它有效,看起来很漂亮,不需要Matlab 2016b。
theta = atan2(rand(1e3,1)-0.5,2*(rand(1e3,1)-0.5));
n = 25;
colours = hsv(n);
figure;
rose(theta,n); cla; % Use this to initialise polar axes
[theta,rho] = rose(theta,n); % Get the histogram edges
theta(end+1) = theta(1); % Wrap around for easy interation
rho(end+1) = rho(1);
hold on;
for j = 1:floor(length(theta)/4)
k = @(j) 4*(j-1)+1; % Change of iterator
h = polar(theta(k(j):k(j)+3),rho(k(j):k(j)+3));
set(h,'color',colours(j,:)); % Set the color
[x,y] = pol2cart(theta(k(j):k(j)+3),rho(k(j):k(j)+3));
h = patch(x,y,'');
set(h,'FaceColor',colours(j,:),'FaceAlpha',0.2);
uistack(h,'down');
end
grid on; axis equal;
title('Coloured polar histogram')