Main Content

在极坐标中绘图

以下示例演示如何在极坐标中创建线图、散点图和直方图。此外,还演示了如何对极坐标图添加注释和更改轴范围。

创建极坐标线图

通过极坐标中的天线以可视方式呈现辐射图。加载文件 antennaData.mat,该文件包含变量 thetarho。变量 rho 用于测量天线对 theta 的每个值的辐射强度。通过使用 polarplot 函数在极坐标中绘制数据图,以可视化方式呈现该辐射图。

load('antennaData.mat')

figure
polarplot(theta,rho)

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type line.

在 R2022a 之前,默认情况下极坐标区不包括度符号。要添加度符号,请使用 pax = gca 获取极坐标区。然后使用 pax.ThetaTickLabel = string(pax.ThetaTickLabel) + char(176) 修改刻度标签。

多个极坐标线图

使用 hold on 保留当前极坐标区,然后通过 polarplot 绘制其他数据图。

rng('default')
noisy = rho + rand(size(rho)); 
hold on
polarplot(theta,noisy)
hold off

Figure contains an axes object with type polaraxes. The polaraxes object contains 2 objects of type line.

为极坐标图添加注释

使用 legendtitle 之类的注释函数,标记与其他可视化类型类似的极坐标图。

legend('Original','With Noise')
title('Antenna Radiation Pattern')

Figure contains an axes object with type polaraxes. The polaraxes object contains 2 objects of type line. These objects represent Original, With Noise.

更改极坐标区范围

默认情况下,在极坐标图中,半径的负值将被绘制为正值。使用 rlimr 坐标轴范围调整为包含负值。

rmin = min(rho);
rmax = max(rho);
rlim([rmin rmax])

Figure contains an axes object with type polaraxes. The polaraxes object contains 2 objects of type line. These objects represent Original, With Noise.

使用 thetalimtheta 坐标轴范围更改为 0 到 180。

thetalim([0 180])

Figure contains an axes object with type polaraxes. The polaraxes object contains 2 objects of type line. These objects represent Original, With Noise.

创建极坐标散点图

在极坐标中绘制风速数据图。加载文件 windData.mat,该文件包含变量 directionspeedhumidityC。通过使用 polarscatter 函数在极坐标中绘制数据图,以可视化方式呈现风速图。

load('windData.mat')
polarscatter(direction,speed)

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type scatter.

包括第三个数据输入以改变标记大小并表示第三个维度。

polarscatter(direction,speed,humidity)

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type scatter.

使用格式化输入调整标记显示属性。

polarscatter(direction,speed,humidity,C,'filled')

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type scatter.

创建极坐标直方图

使用 polarhistogram 函数以可视化方式呈现数据,这将会生成称为风向图的可视化表示。

polarhistogram(direction)

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type histogram. This object represents direction.

指定 bin 确定算法。polarhistogram 函数具有各种确定 bin 数量和 bin 宽度的算法,可从 BinMethod 字段中选择。

polarhistogram(direction,'BinMethod','sqrt')

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type histogram. This object represents direction.

指定 bin 数量和 bin 宽度。

polarhistogram(direction,24,'BinWidth',.5)

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type histogram. This object represents direction.

指定归一化方法并调整显示样式以排除任何填充。

polarhistogram(direction,'Normalization','pdf','DisplayStyle','stairs')

Figure contains an axes object with type polaraxes. The polaraxes object contains an object of type histogram. This object represents direction.

另请参阅

| | | | |