我可以画出相应的隐式的曲线:ContourPlot:风格化的轮廓线
ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}]
但我不能找到一种方法,根据颜色的点的位置的轮廓线。更确切地说,我想用2种颜色对曲线进行着色,具体取决于是否x²+y²< k。
我看着ColorFunction,但这只是为了给轮廓线之间的区域着色。 我无法让ContourStyle接受一个依赖于位置的表达式。
我可以画出相应的隐式的曲线:ContourPlot:风格化的轮廓线
ContourPlot[x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1}]
但我不能找到一种方法,根据颜色的点的位置的轮廓线。更确切地说,我想用2种颜色对曲线进行着色,具体取决于是否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]
}]
也许这样的事情
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]]]}}
产生
谢谢你这个有用的答案。它使用户能够使用连续的颜色,这是对其他答案的很好补充。 – tos
+1好的后期处理。 –
这不能为您的问题提供直接解决方案,但我相信这是有趣的。
使用我认为是未公开的格式(即围绕Line
对象的Function
),可以从ContourPlot
内逐渐着色线条。在内部,这与Heike
所做的相似,但她的解决方案使用顶点号码来查找匹配的坐标,从而允许通过空间位置进行造型,而不是沿着线的位置。
ContourPlot[
x^2 + (2 y)^2 == 1, {x, -1, 1}, {y, -1, 1},
BaseStyle -> {12, Thickness[0.01]},
ContourStyle ->
(Line[#, VertexColors -> ColorData["DeepSeaColors"] /@ [email protected]#] & @@ # &)
]
对于有些不够熟练,较少的信息是更。浪费时间浏览设置轮廓线颜色的方法,直到我偶然看到Roelig编辑的答案。我只需要ContourStyle []。
Show[{ContourPlot[
x^2 + 2 x y Tan[2 # ] - y^2 == 1, {x, -3, 3}, {y, -3.2, 3.2},
ContourStyle -> Green] & /@ Range[-Pi/4, Pi/4, .1]},
Background -> Black]
+1在我意识到自己比我早了整整一个小时就解决了问题后,我删除了我的解决方案(与您的解决方案几乎完全相同)。 – DavidC