主要内容

fpolarplot

在极坐标中绘制表达式或函数

自 R2024a 起

  • Plot expression or function in polar coordinates

说明

fpolarplot(f) 在默认区间 0 ≤ theta ≤ 2π 上以极坐标绘制由表达式或函数 r = f(theta) 定义的曲线。

示例

fpolarplot(f,[a b]) 在指定区间 a ≤ theta ≤ b 绘制 r = f(theta)

示例

fpolarplot(___,LineSpec) 指定线型、标记符号和线条颜色。例如,"-r" 绘制一条红色实线。在上述语法中的任何输入参量组合后使用此选项。

示例

fpolarplot(___,Name=Value) 使用一个或多个名称-值参量指定线条属性。例如,LineWidth=2 指定 2 磅的线宽。

示例

fpolarplot(pax,___) 在由 pax 指定的 PolarAxes 对象(而不是当前坐标区 (gca))中绘图。

fp = fpolarplot(___) 返回 FunctionLine 对象。使用该对象查询和修改所绘制线条的属性。有关属性列表,请参阅 FunctionLine 属性

示例

示例

全部折叠

创建表达式 1+cos(θ) 在区间 0θ2π 上的极坐标图。

f = @(t) 1 + cos(t);
fpolarplot(f)

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

通过将绘图区间指定为 fpolarplot 的第二个输入,绘制 t2 在区间 -2πt2π 上的图。

f = @(t) t.^2;
fpolarplot(f,[-2*pi 2*pi])

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

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

f = @(t) sin(t);
fpolarplot(f)

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

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

rlim([-1 1])

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

在极坐标中绘制三条曲线。第一条曲线使用点划线,第二条曲线使用线宽为 2 的虚线,第三条曲线使用蓝色实线。

fpolarplot(@(t) t.^(1/4),"-.")
hold on
fpolarplot(@(t) t.^(2/3),"--",LineWidth=2)
fpolarplot(@(t) t,"-b")
legend
hold off

Figure contains an axes object with type polaraxes. The polaraxes object contains 3 objects of type functionline.

在极坐标中绘制曲线 r=sin(2θ)cos(2θ),并返回函数线条对象。

f = @(t) sin(2*t).*cos(2*t);
fp = fpolarplot(f)

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

fp = 
  FunctionLine with properties:

     Function: @(t)sin(2*t).*cos(2*t)
        Color: [0.0660 0.4430 0.7450]
    LineStyle: '-'
    LineWidth: 0.5000

  Show all properties

您可以使用圆点表示法访问和修改函数线条对象的属性。例如,更改颜色、线型和线宽。

fp.Color = "r";
fp.LineStyle = ":";
fp.LineWidth = 2;

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

输入参数

全部折叠

要绘制的函数,指定为命名或匿名函数的函数句柄。

指定 r = f(theta) 形式的函数。该函数必须接受向量输入参量,并返回大小相同的向量输出参量。为获得最佳性能,应使用数组运算符而不是矩阵运算符。例如,使用 .* (times) 而不是 * (mtimes)。

示例: fpolarplot(@(theta) theta.*sin(theta)) 在默认区间 theta.*sin(theta) 绘制 [0 2*pi]

极坐标角 theta 的区间,指定为 [a b] 形式的二元素向量。fpolarplot 绘制在指定的区间 a ≤ theta ≤ b 上的图。

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

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

示例: "--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

名称-值参数

全部折叠

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

示例: fpolarplot(f,Marker="o",MarkerFaceColor="red")

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

线条颜色,指定为 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

下表列出了浅色和深色主题中绘图的默认调色板。

调色板调色板颜色

"gem" - 浅色主题默认值

在 R2025a 之前的版本中: 大多数绘图默认使用这些颜色。

Sample of the "gem" color palette

"glow" - 深色主题默认值

Sample of the "glow" color palette

您可以使用 orderedcolorsrgb2hex 函数获取这些调色板的 RGB 三元组和十六进制颜色代码。例如,获取 "gem" 调色板的 RGB 三元组并将其转换为十六进制颜色代码。

RGB = orderedcolors("gem");
H = rgb2hex(RGB);

在 R2023b 之前的版本中: 使用 RGB = get(groot,"FactoryAxesColorOrder") 获取 RGB 三元组。

在 R2024a 之前的版本中: 使用 H = compose("#%02X%02X%02X",round(RGB*255)) 获取十六进制颜色代码。

示例: "blue"

示例: [0 0 1]

示例: "#0000FF"

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

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

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"无标记不适用

标记轮廓颜色,指定为 "auto"、RGB 三元组、十六进制颜色代码、颜色名称或短名称。默认值 "auto" 使用与 Color 属性相同的颜色。

对于自定义颜色,请指定 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"不适用不适用不适用无颜色

下表列出了浅色和深色主题中绘图的默认调色板。

调色板调色板颜色

"gem" - 浅色主题默认值

在 R2025a 之前的版本中: 大多数绘图默认使用这些颜色。

Sample of the "gem" color palette

"glow" - 深色主题默认值

Sample of the "glow" color palette

您可以使用 orderedcolorsrgb2hex 函数获取这些调色板的 RGB 三元组和十六进制颜色代码。例如,获取 "gem" 调色板的 RGB 三元组并将其转换为十六进制颜色代码。

RGB = orderedcolors("gem");
H = rgb2hex(RGB);

在 R2023b 之前的版本中: 使用 RGB = get(groot,"FactoryAxesColorOrder") 获取 RGB 三元组。

在 R2024a 之前的版本中: 使用 H = compose("#%02X%02X%02X",round(RGB*255)) 获取十六进制颜色代码。

标记填充颜色,指定为 "auto"、RGB 三元组、十六进制颜色代码、颜色名称或短名称。"auto" 值使用与 MarkerEdgeColor 属性相同的颜色。

对于自定义颜色,请指定 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"不适用不适用不适用无颜色

下表列出了浅色和深色主题中绘图的默认调色板。

调色板调色板颜色

"gem" - 浅色主题默认值

在 R2025a 之前的版本中: 大多数绘图默认使用这些颜色。

Sample of the "gem" color palette

"glow" - 深色主题默认值

Sample of the "glow" color palette

您可以使用 orderedcolorsrgb2hex 函数获取这些调色板的 RGB 三元组和十六进制颜色代码。例如,获取 "gem" 调色板的 RGB 三元组并将其转换为十六进制颜色代码。

RGB = orderedcolors("gem");
H = rgb2hex(RGB);

在 R2023b 之前的版本中: 使用 RGB = get(groot,"FactoryAxesColorOrder") 获取 RGB 三元组。

在 R2024a 之前的版本中: 使用 H = compose("#%02X%02X%02X",round(RGB*255)) 获取十六进制颜色代码。

示例: [0.3 0.2 0.1]

示例: "green"

示例: "#D2F9A7"

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

版本历史记录

在 R2024a 中推出