Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

python - 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.

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

Convert a 2D line to 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your mistake is that you define xs and ys as independent variables, while they are dependent (x + y = 5). zs is here independent:

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:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...