[英]Matplotlib: how to draw a vertical plane in 3D figure
I want to draw a vertical plane defined by 我想画一个由
5 = x + y
in a 3D figure, using Matplotlib. 在3D图形中,使用Matplotlib。
I had a look at this and this , but no chance. 我看过这个和这个 ,但是没有机会。 I also found
mpl_toolkits.mplot3d.art3d.line_2d_to_3d
at this link , which says 我还在此链接中找到了
mpl_toolkits.mplot3d.art3d.line_2d_to_3d
Convert a 2D line to 3D
将2D线转换为3D
Looked promising to me, but I could not figure out how to use it. 看起来对我很有前途,但我不知道如何使用它。
Now, how would you modify the following code to achieve my objective? 现在,您将如何修改以下代码以实现我的目标?
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
xs = np.linspace(0, 10, 100)
ys = np.linspace(0, 10, 100)
X, Y = np.meshgrid(xs, ys)
Z # ?????????
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
plt.show()
Thanks for you help in advance. 感谢您的帮助。
Your mistake is that you define xs
and ys
as independent variables, while they are dependent (x + y = 5). 您的错误是将
xs
和ys
定义为自变量,而它们是相关的(x + y = 5)。 zs
is here independent: zs
在这里是独立的:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
xs = np.linspace(0, 10, 100)
zs = np.linspace(0, 10, 100)
X, Z = np.meshgrid(xs, zs)
Y = 5 - X
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
plt.show()
Sample output: 样本输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.