朱莉娅的3D矢量绘图

时间:2018-12-20 15:38:56

标签: plot julia

我正在尝试在Julia中绘制EM波(沿z方向传播)矢量场。我环顾四周,看起来像颤抖是我需要使用的,但我尝试了失败的结果。据我了解,(x,y,z)是向量的原点,(u,v,w)是向量本身在(x,y,z)点的原点。这是我到目前为止的内容,但这似乎无法产生正确的情节。我该如何工作?我也愿意尝试其他绘图库。预先感谢。

using Plots; gr()
t = 0; n = 100; k = 1; ω = 1; φ = π/4
x = y = w = zeros(n)
z = range(0, stop=10, length=n)
u = @. cos(k*z - ω*t)
v = @. sin(k*z - ω*t)
quiver(x, y, z, quiver=(u, v, w), projection="3d")

Output

1 个答案:

答案 0 :(得分:0)

我不确定这是否是您想要的结果,但是我设法使您的代码在Julia v1.1中工作:

using PyPlot

pygui(true)

fig = figure()
ax = fig.gca(projection="3d")
t = 0; n = 100; k = 1; ω = 1; φ = π/4
x = y = w = zeros(n)
z = range(0, stop=10, length=n)
u = cos.(k*z .- ω*t)
v = sin.(k*z .- ω*t)
ax.quiver(x,y,z, u,v,w)

enter image description here

或者,带有颜色:

using PyPlot
using Random

function main()
    pygui(true)

    fig = figure()
    ax = fig.gca(projection="3d")
    t = 0; n = 100; k = 1; ω = 1; φ = π/4
    x = y = w = zeros(n)
    z = range(0, stop=10, length=n)
    u = cos.(k*z .- ω*t)
    v = sin.(k*z .- ω*t)
    a = ((u[1], 0.8, 0.5), (u[2], 0.8, 0.5))
    for i in 3:length(u)-2
        a = (a..., (abs(u[i]), 0.8, 0.5))
    end
    c = ((0.4, 0.5, 0.4), (0.4, 0.9, 0.4), (0.1, 0.1, 0.1))
    q = ax.quiver(x,y,z, u,v,w, color = a)
end
main()

enter image description here