在朱莉娅的3D情节中绘制一条线

时间:2015-05-14 15:41:14

标签: matplotlib plot 3d julia

我试图在曲面Z函数x ^ 2 + y ^ 2中绘制点[1,1]和[0,0]之间的线段, 我已经用以下方式绘制了f:

using PyPlot
using Distributions

function f(x)
    return (x[1]^2 + x[2]^2)
    #return sin(x[1]) + cos(x[2])
end

n = 100
x = linspace(-1, 1, n)
y = linspace(-1,1,n)

xgrid = repmat(x',n,1)
ygrid = repmat(y,1,n)

z = zeros(n,n)

for i in 1:n
    for j in 1:n
        z[i:i,j:j] = f([x[i],y[j]])
    end
end

plot_wireframe(xgrid,ygrid,z)

我已经知道R(ggplot2)和C了,但我是python和julia librarys的新手,比如matlibplot

1 个答案:

答案 0 :(得分:0)

好吧,我只需要做:

using PyPlot
using Distributions

function f(x)
    return (x[1]^2 + x[2]^2)
    #return sin(x[1]) + cos(x[2])
end

n = 100
x = linspace(-1, 1, n)
y = linspace(-1,1,n)

xgrid = repmat(x',n,1)
ygrid = repmat(y,1,n)

z = zeros(n,n)

for i in 1:n
    for j in 1:n
        z[i:i,j:j] = f([x[i],y[j]])
    end
end

plot_wireframe(xgrid,ygrid,z)

## new line
plot([0.0, 1.0, -1.0], [0.0, 1.0, 1.0], [0.0 , 2.0, 2.0], color="red")