如何在VectorPlot中将VectorColorFunction分配给相位而不是幅度

问题描述

我想通过将颜色分配给数据点的相位/角度(而不是它们的大小)来绘制2D向量,就像ComplexPlot函数中使用的颜色一样。但是,ComplexPlot没有我喜欢使用的VectorMarker来显示数据点的大小。

这就是我所拥有的

VectorPlot[{x,y},{x,-3,3},{y,VectorMarkers -> "CircleArrow",VectorColorFunction -> Hue]

enter image description here

我也尝试分配VectorColorFunction -> ArcTan[y/x],但这不起作用。

=========== @ mikuszefski建议后的修订==============

我将代码修改为 VectorPlot[{x,VectorColorFunction -> (ColorData["Hue"][Arg[#3 + I #4]] &)]

但是,错误消息显示“ ColorData :: notent:Hue不是ColorData的已知实体,类或标记。将ColorData []用于实体列表。”

我找到了可用的颜色表“彩虹”

VectorPlot[{x,VectorColorFunction -> (ColorData["Rainbow"][Arg[#3 + I #4]] &)] 结果如下:

enter image description here

但是“彩虹”不是适合显示角度的循环色表。无论如何,现在它允许根据角度映射颜色(已定义的函数)。我想下一步是生成一个真实的色相颜色表,可以将其传递给ColorData。

解决方法

查看VectorColorFunction的文档,您可能需要类似的东西

VectorColorFunction -> (ColorData["Rainbow",(Pi + Arg[#3 + I #4])/ (2 Pi) ]&)

VectorPlot自动传递5个参数,它们应该是xyvxvyr,即范数。因此您可以轻松地从矢量分量(即参数3和4)中得到一个创建复数的角度。因此,您必须提供相应的纯函数。与文档中的示例相反,这里我手动调整比例。

信息...我现在没有 Mathematica ,所以我无法测试答案。

更新

似乎HueColorData无效,因此我将上面的代码更改为Rainbow。看着ColorFunction docs得到Hue可能应该阅读

VectorColorFunction -> Function[ { x,y,v,w,r },Hue[ (Pi + Arg[ v + I w ]) / (2 Pi) ] ]

应等于

VectorColorFunction -> ( Hue[ (Pi + Arg[ #3 + I #4 ] ) / (2 Pi) ]& )

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...