在Julia中绘制一个3D垂直平面

huangapple go评论62阅读模式
英文:

Plotting a 3D vertical plane in Julia

问题

我目标是:

[![输入图像描述][1]][1]


  [1]: https://i.stack.imgur.com/hyIF8.png

```julia
using Plots; 
gr()
x=range(-3,stop=3,length=100)
y=range(-3,stop=3,length=100)

X,Y=collect(Iterators.product(x, y))
f(x,y) = 0.5cos.(x./2).*sin.(y./2)
p(y,x) = 3

surface(X,Y,p,surftype=(surface=true, mesh=true))

我尝试创建一个网格以绘制这个垂直平面(因为除此之外无法绘制垂直平面,您无法生成坐标z的显式函数来绘制 - 与其他形状和曲面不同。然而,在Julia中实现这个解决方案对我来说很困难。


<details>
<summary>英文:</summary>

My goal:

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/hyIF8.png

using Plots;
gr()
x=range(-3,stop=3,length=100)
y=range(-3,stop=3,length=100)

X,Y=collect(Iterators.product(x, y))
f(x,y) = 0.5cos.(x./2).*sin.(y./2)
p(y,x) = 3

surface(X,Y,p,surftype=(surface=true, mesh=true))


I have tried creating a meshgrid to plot this vertical plane (seeing as it is impossible to plot vertical planes otherwise, as you can generate an explicit function for coordinate z to plot - unlike other shapes and surfaces. However, implementing this solution in Julia has proven difficult for me. 



</details>


# 答案1
**得分**: 1

如果您只是想绘制这些数据,您可以通过使用非常小的坐标范围来模拟垂直线,就像您示例图像中的x轴一样。

您可以通过以下方式实现所需的绘图:
```julia
using Plots; 
gr()

res = 10
x = y = range(-1*res,stop=res,length=10)
eps_x = range(-1*eps(),stop=eps(),length=10) #创建一个非常小的范围

X = repeat(x,1,length(y))
Y = repeat(y',length(x),1)

all_zeroes = X .* 0

plot(xlabel = "X", ylabel = "Y", zlabel = "Z", xrange = (-1*res,res), yrange = (-1*res,res), zrange = (-1*res,res)) #创建空的3D图

surface!(x,y,all_zeroes, surftype=(surface = true, mesh = true)) #创建水平平面
surface!(eps_x,y,Y, surftype=(surface = true, mesh = true)) #创建“垂直”平面

请注意,gr() 对于重叠的表面效果不佳,即使使用 wireframe!() 代替 surface!() 也是如此。

英文:

If you are simply looking to plot this data, you could imitate a vertical line using a very small axis range, the x axis in your example image.

You can achieve the desired plot in this way using:

using Plots; 
gr()

res = 10
x = y = range(-1*res,stop=res,length=10)
eps_x = range(-1*eps(),stop=eps(),length=10) #create a very small range

X = repeat(x,1,length(y))
Y = repeat(y&#39;,length(x),1)

all_zeroes = X .* 0

plot(xlabel = &quot;X&quot;, ylabel = &quot;Y&quot;, zlabel = &quot;Z&quot;, xrange = (-1*res,res), yrange = (-1*res,res), zrange = (-1*res,res)) #create empty 3d plot

surface!(x,y,all_zeroes, surftype=(surface = true, mesh = true)) #create horizontal plane
surface!(eps_x,y,Y, surftype=(surface = true, mesh = true)) #create &quot;verticle&quot; plane

Keep in mind that gr() doesn't do great with overlapping surfaces, even using wireframe!() instead of surface!()

在Julia中绘制一个3D垂直平面

huangapple
  • 本文由 发表于 2023年6月8日 21:32:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432392.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定