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

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

Plotting a 3D vertical plane in Julia

问题

  1. 我目标是:
  2. [![输入图像描述][1]][1]
  3. [1]: https://i.stack.imgur.com/hyIF8.png
  4. ```julia
  5. using Plots;
  6. gr()
  7. x=range(-3,stop=3,length=100)
  8. y=range(-3,stop=3,length=100)
  9. X,Y=collect(Iterators.product(x, y))
  10. f(x,y) = 0.5cos.(x./2).*sin.(y./2)
  11. p(y,x) = 3
  12. surface(X,Y,p,surftype=(surface=true, mesh=true))

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

  1. <details>
  2. <summary>英文:</summary>
  3. My goal:
  4. [![enter image description here][1]][1]
  5. [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))

  1. 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.
  2. </details>
  3. # 答案1
  4. **得分**: 1
  5. 如果您只是想绘制这些数据,您可以通过使用非常小的坐标范围来模拟垂直线,就像您示例图像中的x轴一样。
  6. 您可以通过以下方式实现所需的绘图:
  7. ```julia
  8. using Plots;
  9. gr()
  10. res = 10
  11. x = y = range(-1*res,stop=res,length=10)
  12. eps_x = range(-1*eps(),stop=eps(),length=10) #创建一个非常小的范围
  13. X = repeat(x,1,length(y))
  14. Y = repeat(y',length(x),1)
  15. all_zeroes = X .* 0
  16. plot(xlabel = "X", ylabel = "Y", zlabel = "Z", xrange = (-1*res,res), yrange = (-1*res,res), zrange = (-1*res,res)) #创建空的3D图
  17. surface!(x,y,all_zeroes, surftype=(surface = true, mesh = true)) #创建水平平面
  18. 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:

  1. using Plots;
  2. gr()
  3. res = 10
  4. x = y = range(-1*res,stop=res,length=10)
  5. eps_x = range(-1*eps(),stop=eps(),length=10) #create a very small range
  6. X = repeat(x,1,length(y))
  7. Y = repeat(y&#39;,length(x),1)
  8. all_zeroes = X .* 0
  9. 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
  10. surface!(x,y,all_zeroes, surftype=(surface = true, mesh = true)) #create horizontal plane
  11. 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:

确定