Main Content

自定义极坐标区

为了便于查看图形,可以修改极坐标区的特定方面。例如,可以更改网格线位置和关联的标签。也可以更改网格线颜色和标签字体大小。

创建极坐标图

在极坐标中绘制线条和添加标题。

theta = linspace(0,2*pi);
rho = 2*theta;
figure
polarplot(theta,rho)
title('My Polar Plot')

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) 修改刻度标签。

使用属性自定义极坐标区

在创建极坐标图时,MATLAB 会创建一个 PolarAxes 对象。PolarAxes 对象具有可用于自定义极坐标区外观的属性,例如字体大小、颜色或刻度。有关完整列表,请参阅 PolarAxes 属性

使用 gca 函数访问 PolarAxes 对象,例如 pax = gca。然后,通过圆点表示法使用 pax 来设置属性,例如 pax.FontSize = 14

pax = gca
pax = 
  PolarAxes (My Polar Plot) with properties:

             ThetaLim: [0 360]
                 RLim: [0 14]
       ThetaAxisUnits: 'degrees'
             ThetaDir: 'counterclockwise'
    ThetaZeroLocation: 'right'

  Use GET to show all properties

pax.FontSize = 14;

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

theta 轴刻度值

沿 theta 轴每隔 45 度显示刻度线。将这些位置指定为一个由递增值组成的向量。

thetaticks(0:45:315)

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

通过设置 ThetaAxisUnits 属性,以弧度(而不是度)为单位显示 theta 轴上的值。

pax = gca;
pax.ThetaAxisUnits = 'radians';

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

修改 theta 轴,使其按顺时针方向增加。此外,还要旋转 theta 轴,以使基准角 0 位于左侧。

pax = gca;
pax.ThetaDir = 'clockwise';
pax.ThetaZeroLocation = 'left';

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

r 坐标轴范围、刻度值和标签

r 轴范围更改为值介于 -5 和 15 之间。在值 -2、3、9 和 15 处显示刻度线。然后,更改每个刻度线旁边显示的标签。将标签指定为字符向量元胞数组。

rlim([-5 15])
rticks([-2 3 9 15])
rticklabels({'r = -2','r = 3','r = 9','r = 15'})

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

网格线和标签颜色

通过设置 ThetaColorRColor 属性,对 theta 轴和 r 轴网格线及关联的标签使用不同的颜色。通过设置 LineWidth 属性,更改网格线的线宽。

使用某个颜色名称(例如 'blue')的字符向量或 RGB 三元组指定颜色。RGB 三元组是包含三个元素的行向量,其元素分别指定颜色中红、绿、蓝分量的强度。强度必须处于范围 [0,1] 中,例如 [0.4 0.6 0.7]。

pax = gca;
pax.ThetaColor = 'blue';
pax.RColor = [0 .5 0];

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

通过设置 GridColor 属性,在不影响标签的情况下更改所有网格线的颜色。

pax.GridColor = 'red';

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

指定 GridColor 属性后,ThetaColorRColor 属性将不再影响网格线。如果希望 ThetaColorRColor 属性影响网格线,则可将 GridColorMode 属性设置回 'auto'

另请参阅

| | | | |

相关主题