You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Julia中绘制3D垂直平面?

在Julia Plots中绘制垂直平面

你当前的代码里,p(y,x)=3画的是z=3的水平面,不是你想要的垂直平面。垂直平面(比如x=常数、y=常数这类)没法用z=f(x,y)的显式函数定义,得换个方式构造网格数据。

解决方案:构造固定坐标的网格

以绘制x=3的垂直平面为例(覆盖y∈[-3,3]、z∈[-1,1]的范围),代码如下:

using Plots; gr()

# 先绘制原曲面f(x,y)
x = range(-3, stop=3, length=100)
y = range(-3, stop=3, length=100)
X_surf, Y_surf = collect(Iterators.product(x, y))
f(x,y) = 0.5cos(x/2)*sin(y/2)
Z_surf = f.(X_surf, Y_surf)

surface(X_surf, Y_surf, Z_surf, label="曲面f(x,y)")

# 构造垂直平面x=3的网格数据
y_plane = range(-3, stop=3, length=100)
z_plane = range(-1, stop=1, length=100)
Y_plane, Z_plane = collect(Iterators.product(y_plane, z_plane))
X_plane = fill(3, size(Y_plane))  # 固定x为3

# 叠加垂直平面
surface!(X_plane, Y_plane, Z_plane, label="垂直平面x=3", color=:red, alpha=0.5)

如果要画y=3的垂直平面,逻辑完全一致,只需要固定y坐标:

# 构造垂直平面y=3的网格数据
x_plane = range(-3, stop=3, length=100)
z_plane = range(-1, stop=1, length=100)
X_plane, Z_plane = collect(Iterators.product(x_plane, z_plane))
Y_plane = fill(3, size(X_plane))  # 固定y为3

surface!(X_plane, Y_plane, Z_plane, label="垂直平面y=3", color=:blue, alpha=0.5)

核心原理

垂直平面的特点是某一个坐标轴的坐标值固定,所以我们只需要:

  • 给另外两个坐标轴生成范围和网格
  • 用fill()把固定的坐标值填充成和网格一样的尺寸
  • 最后用surface!()叠加到原图形上即可

内容的提问来源于stack exchange,提问作者TheTenthBox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:52:15