ContourPlot[f,{x,xmin,xmax},{y,ymin,ymax}]
生成关于 x 和 y 的函数 f 的等高线图.
ContourPlot[f==g,{x,xmin,xmax},{y,ymin,ymax}]
绘制 f=g 的等高线.
ContourPlot[{f1==g1,f2==g2,…},{x,xmin,xmax},{y,ymin,ymax}]
绘制多个等高线.
ContourPlot[…,{x,y}∈reg]
将变量 {x,y} 选在几何区域 reg 中.
ContourPlot
ContourPlot[f,{x,xmin,xmax},{y,ymin,ymax}]
生成关于 x 和 y 的函数 f 的等高线图.
ContourPlot[f==g,{x,xmin,xmax},{y,ymin,ymax}]
绘制 f=g 的等高线.
ContourPlot[{f1==g1,f2==g2,…},{x,xmin,xmax},{y,ymin,ymax}]
绘制多个等高线.
ContourPlot[…,{x,y}∈reg]
将变量 {x,y} 选在几何区域 reg 中.
更多信息和选项
- ContourPlot 亦称为等值线、等位线、等值集 (level set) 或下等值集 (sublevel set).
- 当给定函数 f 时,ContourPlot 构建对应于等值集(其中 f[x,y] 具有恒定的值 d1、d2 等)的等值线. 默认情况下,等值线之间的区域被以有利于识别数值位于 di 和 di+1 之间的区域的方式着色.
- 它可视化的是集合
. - 当给定方程 f==g 时,ContourPlot 显示满足方程的 {x,y} 曲线. 不对区域进行着色;来自多个方程的曲线可以以任意方式相交,着色因此变得毫无意义. 它可视化的是集合
. - 在 f 的计算结果为非实数的位置处,预留空洞,以使等高线图形的背景透过.
- ContourPlot 将变量 x 和 y 视为局部变量,实际上等效于 Block.
- ContourPlot 具有属性 HoldAll,仅在对 x 和 y 赋值后才计算 fi 和 gi.
- 某些情况下,在对 x 和 y 赋值之前,先用 Evaluate 符号式计算 fi 和 gi 更有效.
- 在任何 f 计算为 None 的区域,图形留下空白.
- ContourPlot 的选项与 Graphics 相同,并有以下补充和变化: [所有选项的列表]
- PlotLegends 的典型设置包括:
-
None 不使用图例 Automatic 自动确定图例 Placed[lspec,…] 指定图例位置 - 在缺省设置 ContourShading->Automatic 时,阴影用于 ContourPlot[f,…] 但不用于 ContourPlot[f==g,…].
- ContourPlot[{f1==g1,f2==g2,…},…] 叠加所有与等式 fi==gi 相关的等高线.
- 在绘制一组方程时,ColorData["DefaultPlotColors"] 给出 ContourStyle 使用的默认颜色序列.
- ColorData["DefaultPlotColors"] 给出 ContourStyle 使用的默认颜色序列.
- 对于位于等高线层次之间的区域,在确定对区域如何着色的过程中,ContourPlot 首先查看对 ContourShading 的显式设置,然后查看对 ColorFunction 的设置.
- ContourPlot 首先在由 PlotPoints 指定的等间隔样本点的网格上计算 f,然后使用一种自适应算法进行至多 MaxRecursion 次子划分,来产生平滑等高线.
- 应该认识到由于使用的样本点数量有限,ContourPlot 可能会丢失您的函数的部分特征. 在检测您的结果时,可以尝试提高对 PlotPoints 和 MaxRecursion 的设置.
- 对于 PerformanceGoal 的某些设置,其它专有的选项设置可能会被屏蔽.
- MeshFunctions 和 RegionFunction 中提供给函数的自变量是 x、y、f.
- ColorFunction 缺省下提供单个自变量,它由关于每对连续等高层的 f 的平均比例值给出.
- 在缺省设置 Exclusions->Automatic 和 ExclusionsStyle->None 时,ContourPlot 在它检测到的任何曲线不连续处断开取样的连续性. 这个不连续性仅在它跳离特定等高层时立即显示出来.
- ScalingFunctions 的可能设置包括:
-
sf 缩放 f 值 {sx,sy} 缩放 x 和 y 轴 {sx,sy,sf} 缩放 x 和 y 轴以及 f 值 - 在不同绘图面板中显示每个输入的 PlotLayout 可能设置包括:
-
"Column" 在一列面板中使用不同等值线 "Row" 在一行面板中使用不同等值线 {"Column",k},{"Row",k} 使用 k 列或行 {"Column",UpTo[k]},{"Row",UpTo[k]} 使用至多 k 列或行 - 除了 LightingAngle->None 以外的设定, ContourPlot 包括基于高度值的模拟光源,其中高度值由 BoxRatios 决定.
- ContourPlot 返回 Graphics[GraphicsComplex[data]].
所有选项的列表
范例
打开所有单元 关闭所有单元基本范例 (4)
ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}]ContourPlot[Cos[x] + Cos[y] == 1 / 2, {x, 0, 4Pi}, {y, 0, 4Pi}]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}]ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, PlotLegends -> Automatic]范围 (22)
取样 (11)
ContourPlot[Sin[x y], {x, 0, 2}, {y, 0, 2}, Mesh -> All]ContourPlot[1 / (x ^ 2 + y ^ 2), {x, -1, 1}, {y, -1, 1}]ContourPlot[Sqrt[x y], {x, -1, 1}, {y, -1, 1}]ContourPlot[Im[ArcSin[(x + I y) ^ 3]], {x, -2, 2}, {y, -2, 2}]用 PlotPoints 和 MaxRecursion 控制自适应取样:
Grid[Table[ContourPlot[Sin[x y], {x, 0, 4}, {y, 0, 4}, PlotPoints -> pp, MaxRecursion -> mr], {mr, {0, 2}}, {pp, {5, 15}}]]用 PlotRange 强调感兴趣的区域:
{ContourPlot[x ^ 4 - 2x ^ 2 + y ^ 4 - 2y ^ 2 + 5, {x, -2, 2}, {y, -2, 2}], ContourPlot[x ^ 4 - 2x ^ 2 + y ^ 4 - 2y ^ 2 + 1, {x, -2, 2}, {y, -2, 2}, PlotRange -> {-2, 2}, ClippingStyle -> None]}用 Exclusions 删除曲线或切割生成的曲面:
f = 1 / ChebyshevU[x y - 1, 2];{ContourPlot[f, {x, -2, 2}, {y, -2, 2}, ClippingStyle -> Automatic], ContourPlot[f, {x, -2, 2}, {y, -2, 2}, ClippingStyle -> Automatic, Exclusions -> {x == 0, y == 0}]}用 RegionFunction 将曲面限制在不等式给定的区域上:
ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 0 < x + y ^ 2 < Pi]]ContourPlot[Sin[x + Cos[y]], {x, y}∈Disk[{0, 0}, 3]]还可以通过 MeshRegion 指定定义域:
𝒟 = MeshRegion[{{0, 0}, {5, -2}, {3, 0}, {5, 2}}, Polygon[{1, 2, 3, 4}]];ContourPlot[Sin[x]Cos[y], {x, y}∈𝒟]ContourPlot[(x y^2/x^2 + y^4), {x, -Infinity, Infinity}, {y, -Infinity, Infinity}]演示 (11)
ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, FrameLabel -> {x, y}, PlotLabel -> Sin[x y]]ContourPlot[Sin[x y] == 0, {x, -3, 3}, {y, -3, 3}, FrameLabel -> {x, y}, PlotLabel -> Sin[x y] == 0]ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "Rainbow"]ContourPlot[Sin[x ^ 2 + y ^ 2], {x, -1, 1}, {y, -1, 1}, ContourLabels -> True]ContourPlot[Sin[x ^ 2 + y ^ 2], {x, -1, 1}, {y, -1, 1}, ColorFunction -> "DeepSeaColors", PlotLegends -> Automatic]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> "Expressions"]ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ContourShading -> Hue /@ Range[0, 0.8, 0.8 / 10]]ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, ContourStyle -> {Red, Directive[Red, Dashed]}]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, ContourStyle -> {Red, Dashed}]ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> 3, MeshStyle -> {Red, Blue}, MeshFunctions -> {#1&, #2&}]ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, PlotTheme -> "Business"]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Web"]ContourPlot[{Sin[x]Cos[y], Sin[x + y]Cos[x - y]}, {x, -7, 7}, {y, -7, 7}, PlotLayout -> "Row"]ContourPlot[{Sin[x]Cos[y], Sin[x + y]Cos[x - y]}, {x, -7, 7}, {y, -7, 7}, PlotLayout -> "Column"]选项 (112)
AspectRatio (4)
默认情况下,ContourPlot 使用的相等的宽和高:
ContourPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}]ContourPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> 1 / 2]AspectRatioAutomatic 根据绘图范围决定宽高比:
ContourPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> Automatic]AspectRatioFull 调整宽和高以紧密贴合内部的其他结构:
plot = ContourPlot[Sin[x]Cos[y], {x, -2Pi, 2Pi}, {y, -Pi / 2, 3Pi / 2}, AspectRatio -> Full];
{Framed[Pane[plot, {75, 100}]], Framed[Pane[plot, {100, 100}]], Framed[Pane[plot, {100, 75}]]}Axes (4)
默认情况下,ContourPlot 使用边框而非轴:
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True]使用 AxesOrigin 可指明轴的相交处:
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesOrigin -> {1, 1}]{ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> {True, False}], ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> {False, True}]}AxesLabel (4)
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesLabel -> y]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesLabel -> {x, y}]基于 ContourPlot 中指定的变量使用标签:
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesLabel -> Automatic]AxesOrigin (2)
AxesStyle (4)
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesStyle -> Red]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesStyle -> {Red, Blue}]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesStyle -> Green, TicksStyle -> Blue]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, Frame -> False, Axes -> True, AxesStyle -> Green, LabelStyle -> Blue]BoundaryStyle (5)
ContourPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}]ContourPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red]ContourPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Directive[Red, Thick]]BoundaryStyle 应用到 RegionFunction 切割的空洞上:
ContourPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red, RegionFunction -> Function[{x, y, z}, x ^ 2 + y ^ 2 ≥ 1]]BoundaryStyle 不应用 Exclusions 的切割:
ContourPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, BoundaryStyle -> Red]用 ExclusionsStyle 替代:
ContourPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, ExclusionsStyle -> Red]ClippingStyle (4)
ContourPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> Automatic]ContourPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> None]ContourPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> Pink]ContourPlot[Im[Gamma[x + I y]], {x, -3.5, 3.5}, {y, -3.5, 3.5}, ClippingStyle -> {Pink, LightRed}]ColorFunction (3)
ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> Hue]ContourPlot[y + Sin[x ^ 2 + 3y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "DarkRainbow"]ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, Contours -> {1 / 2}, ColorFunction -> (If[#1 > 1 / 2, Red, White]&)]ColorFunctionScaling (1)
ContourLabels (2)
ContourLines (1)
ContourLines 被 ContourStyle 取代:
{ContourPlot[Sin[x]Sin[y], {x, -2, 2}, {y, -3, 3}, ContourLines -> False], ContourPlot[Sin[x]Sin[y], {x, -2, 2}, {y, -3, 3}, ContourStyle -> None]}Contours (7)
ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> 10]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> Automatic]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> {Automatic, 5}]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> {-0.5, 0.5}]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> {{-0.5, Thick}, {0.5, Dashed}}]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> Function[{min, max}, Range[min, max, 0.1]]]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> Function[{min, max}, Rescale[{0.1, 0.9}, {0, 1}, {min, max}]]]ContourShading (4)
ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourShading -> Automatic]用 None 仅显示等高线:
ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourShading -> None]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourShading -> Automatic, ColorFunction -> "Rainbow"]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, Contours -> 3, ContourShading -> {Red, Orange, Yellow, White}]ContourStyle (7)
ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourStyle -> Automatic]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourStyle -> Opacity[1]]用 None 不显示等高线:
ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourStyle -> None]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourStyle -> {Red, Dashed}]ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, ContourStyle -> Directive[Red, Dashed]]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, ContourStyle -> {Red, Dashed}]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, ContourStyle -> Directive[Red, Dashed]]EvaluationMonitor (2)
显示 ContourPlot 在函数取样的位置:
ListPlot[Reap[ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, EvaluationMonitor :> Sow[{x, y}]]][[-1, 1]], PlotStyle -> PointSize[Tiny]]Block[{k = 0}, ContourPlot[Sin[x]Sin[y], {x, -3, 3}, {y, -3, 3}, EvaluationMonitor :> k++];k]Exclusions (6)
ContourPlot[Im[ArcSin[x + I y]], {x, -2, 2}, {y, -2, 2}]ContourPlot[Im[ArcSin[x + I y]], {x, -2, 2}, {y, -2, 2}, Exclusions -> None]ContourPlot[ 1 / (y ^ 2 - x ^ 3 + 3x - 3), {x, -3, 3}, {y, -3, 3}, Exclusions -> {y ^ 2 - x ^ 3 + 3x - 3 == 0}, ClippingStyle -> Automatic]ContourPlot[Tan[x y] + 1 / (y ^ 2 - x ^ 3 + 3x - 3), {x, -2, 2}, {y, -2, 2}, Exclusions -> {Cos[x y] == 0, y ^ 2 - x ^ 3 + 3x - 3 == 0}, ClippingStyle -> Automatic]ContourPlot[Im[Sqrt[x + I y]], {x, -2, 2}, {y, -2, 2}, Exclusions -> {{y == 0, x ≤ 0}}]ContourPlot[Im[(x + I y) ^ (1 / 3)] / (x ^ 2 - y ^ 2), {x, -2, 2}, {y, -2, 2}, Exclusions -> {Automatic, x ^ 2 - y ^ 2 == 0}, ClippingStyle -> Automatic]//QuietExclusionsStyle (2)
ImageSize (7)
使用有名称的尺寸如 Tiny、Small、Medium 和 Large:
{ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> Tiny], ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> Small]}{ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> 150], ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> 1.5, ImageSize -> 150]}{ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> {Automatic, 150}], ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> 2, ImageSize -> {Automatic, 150}]}{ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> UpTo[200]], ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> 2, ImageSize -> UpTo[200]]}ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> {300, 200}, Background -> StandardGray]设置 AspectRatioFull 图形将会填充可用空间:
ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> Full, ImageSize -> {200, 300}, Background -> StandardGray]{ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> {UpTo[150], UpTo[100]}], ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> 2, ImageSize -> {UpTo[150], UpTo[100]}]}设置 ImageSizeFull 绘图将会填充对象内的可用空间:
Framed[Pane[ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, ImageSize -> Full, AspectRatio -> Full, Background -> StandardGray], {300, 200}]]Framed[Pane[ContourPlot[Cos[x] + Cos[y], {x, 0, 4Pi}, {y, 0, 4Pi}, AspectRatio -> Full, ImageSize -> {Scaled[0.5], Scaled[0.5]}, Background -> StandardGray], {200, 100}]]MaxRecursion (1)
Mesh (2)
{ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> Full], ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> All]}{ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, Mesh -> Full],
ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, Mesh -> All]}ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> 5, MeshFunctions -> {#1&, #2&}]ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, Mesh -> 5, MeshFunctions -> {#1&, #2&}]MeshFunctions (2)
ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshFunctions -> {#1&, #2&}, Mesh -> {5, 5}]ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, MeshFunctions -> {#1&, #2&}, Mesh -> {5, 5}]ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshFunctions -> {Norm[{#1, #2, #3}]&}, Mesh -> 5]ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, MeshFunctions -> {Norm[{#1, #2}]&}, Mesh -> 5]MeshStyle (2)
ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshStyle -> Red, Mesh -> 5, MeshFunctions -> {#1&, #2&}]ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, MeshStyle -> Red, Mesh -> 5, MeshFunctions -> {#1&, #2&}]ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, MeshStyle -> {Red, Thick}, Mesh -> 5, MeshFunctions -> {#1&, #2&}]ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, MeshStyle -> {Red, PointSize[Large]}, Mesh -> 5, MeshFunctions -> {#1&, #2&}]PerformanceGoal (2)
Timing[ContourPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, PerformanceGoal -> "Quality"]]Timing[ContourPlot[Sin[x + y ^ 2] == 0, {x, -2, 2}, {y, -2, 2}, PerformanceGoal -> "Quality"]]Timing[ContourPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, PerformanceGoal -> "Speed"]]Timing[ContourPlot[Sin[x + y ^ 2] == 0, {x, -2, 2}, {y, -2, 2}, PerformanceGoal -> "Speed"]]PlotInteractivity (2)
PlotLayout (2)
ContourPlot[{Sin[x]Cos[y], Sin[2x]Cos[y], Sin[x]Cos[2y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> "Column"]ContourPlot[{Sin[x]Cos[y], Sin[2x]Cos[y], Sin[x]Cos[2y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> "Row"]ContourPlot[{Sin[x]Cos[y], Sin[2x]Cos[y], Sin[x]Cos[2y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Row", 2}]ContourPlot[{Sin[x]Cos[y], Sin[2x]Cos[y], Sin[x]Cos[2y], Cos[x]Sin[y], Cos[2x]Sin[y], Cos[x]Sin[2y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Column", UpTo[4]}]ContourPlot[{Sin[x]Cos[y], Sin[2x]Cos[y], Sin[x]Cos[2y], Cos[x]Sin[y], Cos[2x]Sin[y], Cos[x]Sin[2y]}, {x, -3, 3}, {y, -2, 2}, ImageSize -> Medium, PlotLayout -> {"Column", 4}]PlotLegends (8)
ContourPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, PlotLegends -> Automatic]Table[ContourPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, Contours -> c, PlotLegends -> Automatic], {c, {5, 10, 20}}]ContourPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, PlotLegends -> BarLegend[Automatic, All]]ContourPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, PlotLegends -> BarLegend[Automatic, None]]PlotLegends 自动匹配颜色函数:
ContourPlot[Sin[2 x + y]Cos[x - 2y], {x, 0, Pi}, {y, 0, Pi}, ColorFunction -> "GrayYellowTones", PlotLegends -> Automatic]PlotLegends->Automatic 使用占位符数值对隐式曲线添加标签:
ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic]使用 PlotLegends->"Expressions" 来使用实际方程:
ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> "Expressions"]ContourPlot[{Abs[Sin[x]Sin[y]] == 0.5, Abs[Cos[x]Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 3}, ContourStyle -> {Red, Dashed}, PlotLegends -> {"label1", "label2"}]使用 Placed 来改变图例位置:
Table[ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, PlotLegends -> Placed[Automatic, pos], PlotLabel -> pos], {pos, {Before, After}}]Table[ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, PlotLegends -> Placed[Automatic, pos], PlotLabel -> pos], {pos, {Above, Below}}]使用 BarLegend 来改变图例外观:
ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> 180, LegendFunction -> "Frame", LegendMargins -> 5, LegendLabel -> "z-value"]]PlotPoints (1)
Table[ContourPlot[Sin[x + y ^ 2], {x, -3, 3}, {y, -2, 2}, Mesh -> None, MaxRecursion -> 0, PlotPoints -> pp], {pp, {5, 10, 15, 20}}]Table[ContourPlot[Sin[x + y ^ 2] == 0, {x, -3, 3}, {y, -2, 2}, Mesh -> None, MaxRecursion -> 0, PlotPoints -> pp], {pp, {5, 10, 15, 20}}]PlotRange (5)
ContourPlot[1 / (x ^ 2 + y ^ 2), {x, -2, 2}, {y, -2, 2}]ContourPlot[1 / (x ^ 2 + y ^ 2), {x, -2, 2}, {y, -2, 2}, PlotRange -> All]ContourPlot[Sqrt[1 - x ^ 2 - y ^ 2], {x, -2, 2}, {y, -2, 2}, PlotRange -> Full]ContourPlot[Sqrt[1 - x ^ 2 - y ^ 2], {x, -2, 2}, {y, -2, 2}, PlotRange -> Automatic]{ContourPlot[x ^ 2 - y ^ 2, {x, -4, 4}, {y, -4, 4}], ContourPlot[x ^ 2 - y ^ 2, {x, -4, 4}, {y, -4, 4}, PlotRange -> {-2, 2}]}PlotTheme (1)
RegionFunction (4)
ContourPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 1 < x ^ 2 + y ^ 2 < 4], BoundaryStyle -> Red]ContourPlot[Sin[x + y ^ 2], {x, -2, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, 0 < Mod[x ^ 2 + y ^ 2, 2] < 1], BoundaryStyle -> Red]ContourPlot[Exp[-(x ^ 2 + y ^ 2)], {x, -2, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, x < 0 || y > 0], BoundaryStyle -> Red]ContourPlot[x ^ 2 == y ^ 3 - y / 5, {x, -1, 1}, {y, -1, 1}, RegionFunction -> Function[{x, y}, x ^ 2 + y ^ 2 < 1]]ScalingFunctions (9)
ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Log"}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Reverse"}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Reciprocal"}, PlotRangePadding -> None]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {"Reverse", "Log"}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {"Reverse", None}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, {-Log[#]&, Exp[-#]&}}]ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {"Log", None}, Ticks -> {2 ^ Range[10], Automatic, Automatic}, GridLines -> Automatic]PlotRange 是自动比例的:
ContourPlot[Max[x, y], {x, 0, 10}, {y, 0, 10}, ScalingFunctions -> {None, "Log"}, PlotRange -> {1, 100}]WorkingPrecision (2)
ContourPlot[Sin[x y + 10 ^ 16], {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> MachinePrecision]ContourPlot[Sin[x y + 10 ^ 16] == 0, {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> MachinePrecision]ContourPlot[Sin[x y + 10 ^ 16], {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> 20]ContourPlot[Sin[x y + 10 ^ 16] == 0, {x, 0, 3}, {y, 0, 3}, WorkingPrecision -> 20]应用 (6)
ContourPlot[2x + 3y == 1, {x, -2, 2}, {y, -2, 2}]ContourPlot[x ^ 2 + y ^ 2 == 1, {x, -1, 1}, {y, -1, 1}]ContourPlot[x ^ 2 + (2y) ^ 2 == 1, {x, -1, 1}, {y, -1, 1}]ContourPlot[x ^ 2 == y, {x, -2, 2}, {y, -2, 2}]ContourPlot[x y == 1, {x, -4, 4}, {y, -4, 4}]ContourPlot[x ^ 2 - y ^ 2 == x ^ 3, {x, -2, 2}, {y, -2, 2}]ContourPlot[Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {5}]], {x, 0, 5}, {y, 0, 5}]{min, {steps}} = Reap[NMinimize[{(x - 1) ^ 2 + 100(y - x ^ 2) ^ 2, x ^ 2 + y ^ 2 ≤ 1}, {{x, -1, -1 / 2}, {y, -1, -1 / 2}}, StepMonitor :> Sow[{x, y}], Method -> "DifferentialEvolution"]];ContourPlot[(x - 1) ^ 2 + 100(y - x ^ 2) ^ 2, {x, -1, 1}, {y, -1, 1}, Contours -> Function[{lo, hi}, Exp[Range[0.01, Log[hi], (Log[hi] - 0.01) / 10]]], RegionFunction -> Function[{x, y, z}, x ^ 2 + y ^ 2 ≤ 1], Epilog -> {Green, Line[steps], Red, Point[steps]}]cdf = CDF[NormalDistribution[0, 1], x]CDF[NormalDistribution[0, 1], y]ContourPlot[cdf, {x, -2, 2}, {y, -2, 2}, Contours -> Function[{min, max}, Rescale[{0.1, 0.9}, {0, 1}, {min, max}]], PlotRange -> All]ElectroStaticPotential[q_, p_, r_] := Sum[ (q[[i]]/Norm[r - p[[i]]]), {i, Length[q]}]ElectroStaticPotential[{Subscript[q, 1], Subscript[q, 2]}, {{Subscript[x, 1], Subscript[y, 1]}, {Subscript[x, 2], Subscript[y, 2]}}, {x, y}]//TraditionalFormc = Join[Table[Lighter[Green, i / 4], {i, 0, 3}], Table[Lighter[Orange, i / 4], {i, 3, 0, -1}]];ContourPlot[Evaluate[ElectroStaticPotential[{-1, 1}, {{-1, 0}, {1, 0}}, {x, y}]], {x, -4, 4}, {y, -4, 4}, Contours -> {-0.75, -0.25, -0.1, 0, 0.1, 0.25, 0.75}, PlotRange -> {{-4, 4}, {-4, 4}, {-1, 1}}, ClippingStyle -> Automatic, ContourShading -> c]ContourPlot[Evaluate[ElectroStaticPotential[{-1, -1, 2}, {{-1, -1}, {-1, 1}, {1, 0}}, {x, y}]], {x, -4, 4}, {y, -4, 4}, Contours -> {-0.75, -0.25, -0.1, 0, 0.1, 0.25, 0.75}, PlotRange -> {{-4, 4}, {-4, 4}, {-1, 1}}, ClippingStyle -> Automatic, ContourShading -> c ]属性和关系 (6)
ContourPlot 在需要处取较多的采样点:
ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, Mesh -> All]用 ListContourPlot 绘制数据:
data = Table[Sin[x y], {x, 0, 3, .1}, {y, 0, 3, .1}];ListContourPlot[data]对表面和密度用 Plot3D 和 DensityPlot:
{Plot3D[Sin[x y], {x, -2, 2}, {y, -2, 2}],
DensityPlot[Sin[x y], {x, -2, 2}, {y, -2, 2}]}对单变量函数用 Plot:
Plot[Sin[x] + Sin[Sqrt[2]x], {x, 0, 20}]对平面参数曲线和区域用 ParametricPlot:
{ParametricPlot[{Cos[θ], Sin[θ]}, {θ, 0, 2Pi}], ParametricPlot[{r Cos[θ], r Sin[θ]}, {θ, 0, 2Pi}, {r, 1 / 2, 1}]}对隐式表面和区域用 ContourPlot3D 和 RegionPlot3D:
{ContourPlot3D[Sin[x y] == z, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}],
RegionPlot3D[Sin[x y] ≥ z, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]}可能存在的问题 (2)
ContourPlot[1 / x + 1 / y == 0, {x, -1, 1}, {y, -1, 1}]f[x_ ? NumberQ, y_ ? NumberQ] := Boole[x ^ 2 + y ^ 2 ≤ 1]ContourPlot[f[x, y] == 0, {x, -1, 1}, {y, -1, 1}]ContourPlot[f[x, y] == 0.5, {x, -1, 1}, {y, -1, 1}]巧妙范例 (3)
ContourPlot[Evaluate[Re[Product[x + I y - (a + I b), {a, -2, 2}, {b, -2, 2}]]], {x, -3, 3}, {y, -3, 3}]Table[ContourPlot[Evaluate[Sum[Product[Norm[{x, y} - RandomReal[{-3, 3}, {2}]], {i, j}] / Product[Norm[{x, y} - RandomReal[{-3, 3}, {2}]], {i, j}], {j, 1, 5}]], {x, -5, 5}, {y, -5, 5}, Contours -> 50, ColorFunction -> (Hue[#]&), ClippingStyle -> Automatic, FrameTicks -> None], {3}]Table[ContourPlot[Re[f[x + I y]], {x, -Pi, Pi}, {y, -Pi, Pi}, PlotLabel -> f, FrameTicks -> {{-Pi, 0, Pi}, {-Pi, 0, Pi}}, ClippingStyle -> Automatic, ColorFunction -> "Pastel"], {f, {ArcSin, ArcCos, ArcCsc, ArcSec, ArcTan, ArcCot}}]技术笔记
-
▪
- 密度图和等高图
历史
1988年引入 (1.0) | 在以下年份被更新:2007 (6.0) ▪ 2008 (7.0) ▪ 2012 (9.0) ▪ 2014 (10.0) ▪ 2016 (11.0) ▪ 2017 (11.1) ▪ 2021 (13.0) ▪ 2025 (14.3)
文本
Wolfram Research (1988),ContourPlot,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ContourPlot.html (更新于 2025 年).
CMS
Wolfram 语言. 1988. "ContourPlot." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/ContourPlot.html.
APA
Wolfram 语言. (1988). ContourPlot. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ContourPlot.html 年
BibTeX
@misc{reference.wolfram_2026_contourplot, author="Wolfram Research", title="{ContourPlot}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/ContourPlot.html}", note=[Accessed: 04-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_contourplot, organization={Wolfram Research}, title={ContourPlot}, year={2025}, url={https://reference.wolfram.com/language/ref/ContourPlot.html}, note=[Accessed: 04-September-2026]}