我可以绘制对应于隐式方程的曲线:
ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}]
但我找不到根据点的位置为等高线着色的方法。更准确地说,我想用两种颜色给曲线上色,这取决于 x² + y² < k 与否。
我查看了 ColorFunction,但这仅用于为等高线之间的区域着色。 而且我无法让 ContourStyle 接受位置相关的表达式。
最佳答案
您可以使用 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]
}]
关于wolfram-mathematica - 轮廓图 : Styling contour lines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8963095/