ContourPlot:造型轮廓线

tos*_*tos 2 wolfram-mathematica

我可以绘制对应于隐式方程的曲线:

ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}]
Run Code Online (Sandbox Code Playgroud)

但是我找不到根据点的位置给轮廓线着色的方法.更准确地说,我想用两种颜色对曲线着色,这取决于是否x²+y²<k.

我查看了ColorFunction,但这仅用于着色轮廓线之间的区域.而且我无法让ContourStyle接受依赖于位置的表达式.

Mar*_*lig 7

你可以用RegionFunction两个分割情节:

Show[{
  ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}, 
  RegionFunction -> Function[{x, y, z}, x^2 + y^2 < .5], 
  ContourStyle -> Red], 
  ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}, 
  RegionFunction -> Function[{x, y, z}, x^2 + y^2 >= .5], 
  ContourStyle -> Green]
}]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形


Hei*_*ike 6

也许这样的事情

pl = ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}]
points = pl[[1, 1]];
colorf[{x_, y_}] := ColorData["Rainbow"][Rescale[x, {-1, 1}]]
pl /. {Line[a_] :> {Line[a, VertexColors -> colorf /@ points[[a]]]}}
Run Code Online (Sandbox Code Playgroud)

哪个产生

Mathematica图形