Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

polarplot

在极坐标中绘制线条

  • Plot line in polar coordinates

说明

向量和矩阵数据

示例

polarplot(theta,rho) 在极坐标中绘制线条,由 theta 表示弧度角,rho 表示每个点的半径值。输入必须为长度相等的向量或大小相等的矩阵。如果输入为矩阵,polarplot 将绘制 rho 的列对 theta 的列的图。也可以一个输入为向量,另一个为矩阵,但向量的长度必须与矩阵的一个维度相等。

示例

polarplot(theta,rho,LineSpec) 设置线条的线型、标记符号和颜色。

polarplot(theta1,rho1,...,thetaN,rhoN) 绘制多个 rho,theta 对组。

polarplot(theta1,rho1,LineSpec1,...,thetaN,rhoN,LineSpecN) 指定每个线条的线型、标记符号和颜色。

示例

polarplot(rho) 按等间距角度(介于 0 和 2π 之间)绘制 rho 中的半径值。

polarplot(rho,LineSpec) 设置线条的线型、标记符号和颜色。

示例

polarplot(Z) 绘制 Z 中的复数值。

polarplot(Z,LineSpec) 设置线条的线型、标记符号和颜色。

表数据

示例

polarplot(tbl,thetavar,rhovar) 绘制表 tbl 中的变量 thetavarrhovar。要绘制一个数据集,请为 thetavar 指定一个变量,为 rhovar 指定一个变量。要绘制多个数据集,请为 thetavarrhovar 或两者指定多个变量。如果两个参数都指定多个变量,它们指定的变量数目必须相同。(自 R2022a 开始提供)

polarplot(tbl,rhovar) 按等间距角度(介于 0 和 2π 之间)绘制 rhovar 中的半径值。此语法不支持时间表。(自 R2022a 开始)

其他选项

polarplot(pax,___) 使用 pax 指定的 PolarAxes 对象,而不是使用当前坐标区。

polarplot(___,Name,Value) 使用一个或多个 Name,Value 对组参数指定图形线条的属性。属性设置适用于所有线条。无法使用 Name,Value 对组为不同的线条指定不同的属性值。

示例

p = polarplot(___) 返回一个或多个图形线条对象。在创建图形线条对象之后使用 p 为其设置属性。有关属性列表,请参阅 Line 属性

示例

全部折叠

在极坐标中绘制线条。

theta = 0:0.01:2*pi;
rho = sin(2*theta).*cos(2*theta);
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) 修改刻度标签。

创建要绘图的数据。

theta = linspace(0,360,50);
rho = 0.005*theta/10;

theta 中的值从度转换为弧度。然后在极坐标中绘制数据。

theta_radians = deg2rad(theta);
polarplot(theta_radians,rho)

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

在极坐标中绘制两个线条。第二个线条使用虚线。

theta = linspace(0,6*pi);
rho1 = theta/10;
polarplot(theta,rho1)

rho2 = theta/12;
hold on
polarplot(theta,rho2,'--')
hold off

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

只指定半径值,不指定角度值。polarplot 将按照等间距角度(从 0 到 2π)绘制半径值。在每个数据点处显示一个圆形标记。

rho = 10:5:70;
polarplot(rho,'-o')

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

使用负半径值创建极坐标图。默认情况下,polarplot 会将负值反射穿过原点。

theta = linspace(0,2*pi);
rho = sin(theta);
polarplot(theta,rho)

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

更改 r 轴的范围,使其从 -1 到 1。

rlim([-1 1])

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

使用带有圆形标记的红色线条创建一个极坐标图。

theta = linspace(0,2*pi,25);
rho = 2*theta;
polarplot(theta,rho,'r-o')

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

创建一个极坐标图并返回图形线条对象。

theta = linspace(0,2*pi,25);
rho = 2*theta;
p = polarplot(theta,rho);

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

更改线条颜色和宽度并添加标记。

p.Color = 'magenta';
p.Marker = 'square';
p.MarkerSize = 8;

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

在极坐标中绘制复数值。在每个点处显示标记,标记间无连接线。

Z = [2+3i 2 -1+4i 3-4i 5+2i -4-2i -2+3i -2 -3i 3i-2i];
polarplot(Z,'*')

Figure contains an axes object with type polaraxes. The polaraxes contains a line object which displays its values using only markers.

基于表数据绘图的一种便捷方法是将表传递给 polarplot 函数,并指定要绘制的变量。

创建一个包含两个变量的表。然后显示该表的前三行。

Angle = linspace(0,3*pi,50)';
Radius = (1:50)';
tbl = table(Angle,Radius);
head(tbl,3)
     Angle     Radius
    _______    ______

          0      1   
    0.19234      2   
    0.38468      3   

绘制 AngleRadius 变量。以 p 形式返回 Line 对象。

p = polarplot(tbl,"Angle","Radius");

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

要修改线条的各个方面,请对 Line 对象设置 LineStyleColorMarker 属性。例如,将线条更改为具有圆形标记的红色点线。

p.LineStyle = ":";
p.Color = "red";
p.Marker = "o";

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

创建一个包含三个变量的表。然后显示表中的前三行。

Angle = linspace(0,3*pi,50)';
Radius1 = (1:50)';
Radius2 = Radius1/2;
tbl = table(Angle,Radius1,Radius2);
head(tbl,3)
     Angle     Radius1    Radius2
    _______    _______    _______

          0       1         0.5  
    0.19234       2           1  
    0.38468       3         1.5  

绘制 AngleRadius1 变量对 Radius2 变量的图。添加一个图例。请注意,图例标签与变量名称匹配。

polarplot(tbl,"Angle",["Radius1" "Radius2"])
legend

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

输入参数

全部折叠

角度值,指定为向量或矩阵。指定弧度值。要将数据从度转换为弧度,请使用 deg2rad

要更改 theta 轴的范围,请使用 thetalim

示例: [0 pi/2 pi 3*pi/2 2*pi]

半径值,指定为向量或矩阵。默认情况下,负值将反射穿过原点。点的反射通过取其半径的绝对值并将其角度增加 180 度来实现。

要更改 r 轴的范围,请使用 rlim

示例: [1 2 3 4 5]

复数值,指定为向量或矩阵,每个元素的形式为 rho*ei*thetax+iy,其中:

  • rho = sqrt(x^2+y^2)

  • theta = atan(y/x)

示例: [1+2i 3+4i 3i]

线型、标记和颜色,指定为包含符号的字符串标量或字符向量。符号可以按任意顺序显示。您不需要同时指定所有三个特征(线型、标记和颜色)。例如,如果忽略线型,只指定标记,则绘图只显示标记,不显示线条。

示例: "--or" 是带有圆形标记的红色虚线。

线型描述表示的线条
"-"实线

Sample of solid line

"--"虚线

Sample of dashed line

":"点线

Sample of dotted line

"-."点划线

Sample of dash-dotted line, with alternating dashes and dots

标记描述生成的标记
"o"圆圈

Sample of circle marker

"+"加号

Sample of plus sign marker

"*"星号

Sample of asterisk marker

"."

Sample of point marker

"x"叉号

Sample of cross marker

"_"水平线条

Sample of horizontal line marker

"|"垂直线条

Sample of vertical line marker

"square"方形

Sample of square marker

"diamond"菱形

Sample of diamond marker

"^"上三角

Sample of upward-pointing triangle marker

"v"下三角

Sample of downward-pointing triangle marker

">"右三角

Sample of right-pointing triangle marker

"<"左三角

Sample of left-pointing triangle marker

"pentagram"五角形

Sample of pentagram marker

"hexagram"六角形

Sample of hexagram marker

颜色名称短名称RGB 三元组外观
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

包含要绘制的数据的源表,指定为表或时间表。

包含 theta 值的表变量,使用下表中的索引方案之一指定。

索引方案示例

变量名称:

  • 字符串、字符向量或元胞数组。

  • pattern 对象。

  • "A"'A' - 名为 A 的变量

  • ["A","B"]{'A','B'} - 两个名为 AB 的变量

  • "Var"+digitsPattern(1) - 变量名为 "Var" 后跟一个数字

变量索引:

  • 引用变量在表中位置的索引编号。

  • 由数字组成的向量。

  • 逻辑向量。通常,此向量的长度与变量的数目相同,但可以省略尾部的 0false 值。

  • 3 - 表中的第三个变量

  • [2 3] - 表中的第二个和第三个变量

  • [false false true] - 第三个变量

变量类型:

  • vartype 下标,用于选择指定类型的变量。

  • vartype("categorical") - 包含分类值的所有变量

您指定的表变量可以包含任何实数值数据类型。如果 thetavarrhovar 都指定多个变量,则变量的数目必须相同。

示例: polarplot(tbl,["th1","th2"],"rho") 为 theta 坐标指定名为 th1th2 的表变量。

示例: polarplot(tbl,2,"rho") 为 theta 坐标指定第二个变量。

示例: polarplot(tbl,vartype("numeric"),"rho") 为 theta 坐标指定所有数值变量。

包含 rho 值的表变量,使用下表中的索引方案之一指定。

索引方案示例

变量名称:

  • 字符串、字符向量或元胞数组。

  • pattern 对象。

  • "A"'A' - 名为 A 的变量

  • ["A","B"]{'A','B'} - 两个名为 AB 的变量

  • "Var"+digitsPattern(1) - 变量名为 "Var" 后跟一个数字

变量索引:

  • 引用变量在表中位置的索引编号。

  • 由数字组成的向量。

  • 逻辑向量。通常,此向量的长度与变量的数目相同,但可以省略尾部的 0false 值。

  • 3 - 表中的第三个变量

  • [2 3] - 表中的第二个和第三个变量

  • [false false true] - 第三个变量

变量类型:

  • vartype 下标,用于选择指定类型的变量。

  • vartype("categorical") - 包含分类值的所有变量

您指定的表变量可以包含任何实数值数据类型。如果 thetavarrhovar 都指定多个变量,则变量的数目必须相同。

示例: polarplot(tbl,"theta",["rho1","rho2"]) 为半径值指定名为 rho1rho2 的表变量。

示例: polarplot(tbl,"theta",2) 指定半径值的第二个变量。

示例: polarplot(tbl,"theta",vartype("numeric")) 指定半径值的所有数值变量。

PolarAxes 对象。您可以通过设置 PolarAxes 对象的属性来修改其外观和行为。有关属性列表,请参阅 PolarAxes 属性

名称-值参数

将可选的参数对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参数名称,Value 是对应的值。名称-值参数必须出现在其他参数之后,但参数对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: 'LineWidth',3

Name,Value 对组设置会应用于绘制的所有线条。不能使用此语法为每个线条指定不同的 Name,Value 对组。可以通过返回图形线条对象,然后使用圆点表示法来设置每个线条的属性。

此处所列的属性只是一部分。有关完整列表,请参阅 Line 属性

线条颜色,指定为 RGB 三元组、十六进制颜色代码、颜色名称或短名称。

对于自定义颜色,请指定 RGB 三元组或十六进制颜色代码。

  • RGB 三元组是包含三个元素的行向量,其元素分别指定颜色中红、绿、蓝分量的强度。强度值必须位于 [0,1] 范围内,例如 [0.4 0.6 0.7]

  • 十六进制颜色代码是字符串标量或字符向量,以井号 (#) 开头,后跟三个或六个十六进制数字,范围可以是 0F。这些值不区分大小写。因此,颜色代码 "#FF8800""#ff8800""#F80""#f80" 是等效的。

此外,还可以按名称指定一些常见的颜色。下表列出了命名颜色选项、等效 RGB 三元组和十六进制颜色代码。

颜色名称短名称RGB 三元组十六进制颜色代码外观
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

"none"不适用不适用不适用无颜色

以下是 MATLAB® 在许多类型的绘图中使用的默认颜色的 RGB 三元组和十六进制颜色代码。

RGB 三元组十六进制颜色代码外观
[0 0.4470 0.7410]"#0072BD"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

线型,指定为下表中列出的选项之一。

线型描述表示的线条
"-"实线

Sample of solid line

"--"虚线

Sample of dashed line

":"点线

Sample of dotted line

"-."点划线

Sample of dash-dotted line, with alternating dashes and dots

"none"无线条无线条

线宽,指定为以磅为单位的正值,其中 1 磅 = 1/72 英寸。如果该线条具有标记,则线条宽度也会影响标记边。

线宽不能小于像素的宽度。如果将线宽设置为小于系统上像素宽度的值,则线条显示为一个像素的宽度。

标记符号,指定为下表中列出的值之一。默认情况下,对象不显示标记。指定标记符号可在每个数据点或顶点添加标记。

标记描述生成的标记
"o"圆圈

Sample of circle marker

"+"加号

Sample of plus sign marker

"*"星号

Sample of asterisk marker

"."

Sample of point marker

"x"叉号

Sample of cross marker

"_"水平线条

Sample of horizontal line marker

"|"垂直线条

Sample of vertical line marker

"square"方形

Sample of square marker

"diamond"菱形

Sample of diamond marker

"^"上三角

Sample of upward-pointing triangle marker

"v"下三角

Sample of downward-pointing triangle marker

">"右三角

Sample of right-pointing triangle marker

"<"左三角

Sample of left-pointing triangle marker

"pentagram"五角形

Sample of pentagram marker

"hexagram"六角形

Sample of hexagram marker

"none"无标记不适用

标记大小,指定为以磅为单位的正值,其中 1 磅 = 1/72 英寸。

标记填充颜色,指定为 "auto"、RGB 三元组、十六进制颜色代码、颜色名称或短名称。"auto" 选项使用与父坐标区的 Color 属性相同的颜色。如果您指定 "auto",并且坐标区图框不可见,则标记填充颜色为图窗的颜色。

对于自定义颜色,请指定 RGB 三元组或十六进制颜色代码。

  • RGB 三元组是包含三个元素的行向量,其元素分别指定颜色中红、绿、蓝分量的强度。强度值必须位于 [0,1] 范围内,例如 [0.4 0.6 0.7]

  • 十六进制颜色代码是字符串标量或字符向量,以井号 (#) 开头,后跟三个或六个十六进制数字,范围可以是 0F。这些值不区分大小写。因此,颜色代码 "#FF8800""#ff8800""#F80""#f80" 是等效的。

此外,还可以按名称指定一些常见的颜色。下表列出了命名颜色选项、等效 RGB 三元组和十六进制颜色代码。

颜色名称短名称RGB 三元组十六进制颜色代码外观
"red""r"[1 0 0]"#FF0000"

Sample of the color red

"green""g"[0 1 0]"#00FF00"

Sample of the color green

"blue""b"[0 0 1]"#0000FF"

Sample of the color blue

"cyan" "c"[0 1 1]"#00FFFF"

Sample of the color cyan

"magenta""m"[1 0 1]"#FF00FF"

Sample of the color magenta

"yellow""y"[1 1 0]"#FFFF00"

Sample of the color yellow

"black""k"[0 0 0]"#000000"

Sample of the color black

"white""w"[1 1 1]"#FFFFFF"

Sample of the color white

"none"不适用不适用不适用无颜色

以下是 MATLAB 在许多类型的绘图中使用的默认颜色的 RGB 三元组和十六进制颜色代码。

RGB 三元组十六进制颜色代码外观
[0 0.4470 0.7410]"#0072BD"

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980]"#D95319"

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

[0.9290 0.6940 0.1250]"#EDB120"

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

[0.4940 0.1840 0.5560]"#7E2F8E"

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

[0.4660 0.6740 0.1880]"#77AC30"

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

[0.3010 0.7450 0.9330]"#4DBEEE"

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840]"#A2142F"

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

提示

  • 要将数据从度转换为弧度,请使用 deg2rad。要将数据从弧度转换为度,请使用 rad2deg

  • 您可以修改极坐标区属性以自定义图表。有关属性列表,请参阅 PolarAxes 属性

  • 要在极坐标区中绘制其他数据,请使用 hold on 命令。但是,不能在极坐标图中绘制需要笛卡尔坐标区的数据。

版本历史记录

在 R2016a 中推出

全部展开