在 MATLAB 中创建 angular(方位角)数据的半圆图
Creating a semicircle plot of angular (azimuth) data in MATLAB
我想使用 MATLAB 创建一个图形,其中绘制了多个数据点,使得它们的方向(方位角 <180 度)在圆周上,它们的宽度在半径上。我画了一张我的意图的草图。
示例数据:
方向(度)/厚度(cm)
098/50
150/87
023/64
这在 MATLAB 中可行吗?
您可以使用 polarplot
function in MATLAB versions starting from R2016a. For older versions you can use the polar
功能,尽管它在修改绘图以使其看起来像您想要的方式方面非常有限。即使使用 polarplot
,您可能会发现很难按照上面显示的方式 完全 创建绘图,但您可以制作非常相似的东西:
% Plot data:
data = [98 50; 150 87; 23 64];
p = polarplot(data(:,1).*pi./180, data(:,2), 'kx', 'LineWidth', 2);
% Adjust axes properties:
set(gca, 'ThetaDir', 'clockwise', 'ThetaZeroLocation', 'top', 'ThetaLim', [0 180], ...
'ThetaTick', 0:45:180, 'ThetaColor', [0 0 0], 'ThetaGrid', 'off');
set(gca, 'LineWidth', 2, 'GridAlpha', 1, 'GridColor', [1 0 0]);
set(gca, 'RLim', [0 100], 'RTick', 0:50:100, 'RAxisLocation', 0, 'RColor', [1 0 0]);
% Set axes labels:
set(get(get(gca, 'RAxis'), 'Label'), 'String', 'Thickness');
set(get(get(gca, 'ThetaAxis'), 'Label'), 'String', 'Orientation', ...
'Position', [90 120 0], 'Rotation', -90);
剧情如下:
这里有一个没有 polarplot
的选项。这有点多,但高度可调:
% Preparations:
data = [98 50; 150 87; 23 64];
thickness = 0:50:100;
azimuth = 0:45:180;
Xax = [min(thickness) max(thickness)]; % X axis limits
Yax = [-max(thickness) max(thickness)]; % Y axis limits
% set the circle:
figure('Position',[200 200 300 400])
pos = [Yax(1) Yax(1) [2 2]*range(thickness)];
rectangle('Position',pos,'Curvature',[1 1],...
'FaceColor',[1 1 1],'LineWidth',3)
axis equal
set(gca,'Color','none');
% thickness line, tick lables and axis label
line(Xax,[0 0],'LineWidth',1,'Color','r')
text(thickness-3,zeros(1,numel(thickness)),num2str(thickness.'),...
'FontSize',16,'Color','r','VerticalAlignment','Bottom',...
'HorizontalAlignment','right')
text(mean(thickness),0,'Thickness','FontSize',14,...
'Color','r','VerticalAlignment','Top',...
'HorizontalAlignment','center')
set(get(gca,'XAxis'),{'Limits','Visible'},{Xax,'off'});
% Azimuth line, tick lables and axis label
line([0 0],Yax,'LineWidth',3,'Color','k')
set(get(gca,'YAxis'),{'Limits','TickValues','TickLabels','FontSize'},...
{Yax,Yax,[max(azimuth) min(azimuth)],14});
azimuth_thicks = azimuth(2:end-1); % get all the ticks yet to plot
azx = max(thickness)*sind(azimuth_thicks);
azy = max(thickness)*cosd(azimuth_thicks);
text(azx+2,azy,num2str(azimuth_thicks.'),'FontSize',14,...
'VerticalAlignment','middle',...
'HorizontalAlignment','Left')
text(max(thickness)*1.25,0,'Orientation','FontSize',16,'Rotation',90,...
'VerticalAlignment','middle',...
'HorizontalAlignment','Center')
% the data points:
x = data(:,2).*sind(data(:,1));
y = data(:,2).*cosd(data(:,1));
L = line(x,y,'Marker','x','LineStyle','none','Color','k',...
'MarkerSize',10,'LineWidth',2);
我想使用 MATLAB 创建一个图形,其中绘制了多个数据点,使得它们的方向(方位角 <180 度)在圆周上,它们的宽度在半径上。我画了一张我的意图的草图。
示例数据:
方向(度)/厚度(cm)
098/50
150/87
023/64
这在 MATLAB 中可行吗?
您可以使用 polarplot
function in MATLAB versions starting from R2016a. For older versions you can use the polar
功能,尽管它在修改绘图以使其看起来像您想要的方式方面非常有限。即使使用 polarplot
,您可能会发现很难按照上面显示的方式 完全 创建绘图,但您可以制作非常相似的东西:
% Plot data:
data = [98 50; 150 87; 23 64];
p = polarplot(data(:,1).*pi./180, data(:,2), 'kx', 'LineWidth', 2);
% Adjust axes properties:
set(gca, 'ThetaDir', 'clockwise', 'ThetaZeroLocation', 'top', 'ThetaLim', [0 180], ...
'ThetaTick', 0:45:180, 'ThetaColor', [0 0 0], 'ThetaGrid', 'off');
set(gca, 'LineWidth', 2, 'GridAlpha', 1, 'GridColor', [1 0 0]);
set(gca, 'RLim', [0 100], 'RTick', 0:50:100, 'RAxisLocation', 0, 'RColor', [1 0 0]);
% Set axes labels:
set(get(get(gca, 'RAxis'), 'Label'), 'String', 'Thickness');
set(get(get(gca, 'ThetaAxis'), 'Label'), 'String', 'Orientation', ...
'Position', [90 120 0], 'Rotation', -90);
剧情如下:
这里有一个没有 polarplot
的选项。这有点多,但高度可调:
% Preparations:
data = [98 50; 150 87; 23 64];
thickness = 0:50:100;
azimuth = 0:45:180;
Xax = [min(thickness) max(thickness)]; % X axis limits
Yax = [-max(thickness) max(thickness)]; % Y axis limits
% set the circle:
figure('Position',[200 200 300 400])
pos = [Yax(1) Yax(1) [2 2]*range(thickness)];
rectangle('Position',pos,'Curvature',[1 1],...
'FaceColor',[1 1 1],'LineWidth',3)
axis equal
set(gca,'Color','none');
% thickness line, tick lables and axis label
line(Xax,[0 0],'LineWidth',1,'Color','r')
text(thickness-3,zeros(1,numel(thickness)),num2str(thickness.'),...
'FontSize',16,'Color','r','VerticalAlignment','Bottom',...
'HorizontalAlignment','right')
text(mean(thickness),0,'Thickness','FontSize',14,...
'Color','r','VerticalAlignment','Top',...
'HorizontalAlignment','center')
set(get(gca,'XAxis'),{'Limits','Visible'},{Xax,'off'});
% Azimuth line, tick lables and axis label
line([0 0],Yax,'LineWidth',3,'Color','k')
set(get(gca,'YAxis'),{'Limits','TickValues','TickLabels','FontSize'},...
{Yax,Yax,[max(azimuth) min(azimuth)],14});
azimuth_thicks = azimuth(2:end-1); % get all the ticks yet to plot
azx = max(thickness)*sind(azimuth_thicks);
azy = max(thickness)*cosd(azimuth_thicks);
text(azx+2,azy,num2str(azimuth_thicks.'),'FontSize',14,...
'VerticalAlignment','middle',...
'HorizontalAlignment','Left')
text(max(thickness)*1.25,0,'Orientation','FontSize',16,'Rotation',90,...
'VerticalAlignment','middle',...
'HorizontalAlignment','Center')
% the data points:
x = data(:,2).*sind(data(:,1));
y = data(:,2).*cosd(data(:,1));
L = line(x,y,'Marker','x','LineStyle','none','Color','k',...
'MarkerSize',10,'LineWidth',2);