【发布时间】:2016-01-14 19:43:34
【问题描述】:
我需要生成一个具有相交平面的图,类似于问题中提出的图:How to draw intersecting planes?。该问题的公认答案是tcaswell 的一段很棒的代码(代码如下)。
在该代码中,使用了一个 var angle,它显然控制了每个平面之间的角度。对于较小的值,它的行为当然是这样,但对于较大的值,它不会。
例如,这些是值 angle = 0.25, 0.5, 1, 5, 50, 100 的结果。
变量显然对平面之间的角度有影响,但它也控制斜面的延伸。起初我虽然angles 用弧度表示,但事实并非如此。它也没有以度数表示,如上图所示,它似乎从未达到平面之间的 90º 角。
接下来的问题是:该变量在做什么?以及:如何控制平面之间的角度?
代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
dim = 10
# Define x,y plane.
X, Y = np.meshgrid([-dim, dim], [-dim, dim])
Z = np.zeros((2, 2))
# Define inclined plane.
angle = 0.5 # <-- This is the variable
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * angle
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * angle
# Plot x,y plane.
ax.plot_surface(X, Y, Z, color='gray', alpha=.5, linewidth=0, zorder=1)
# Plot top half of inclined plane.
ax.plot_surface(X2, Y2, Z2, color='blue', alpha=.5, linewidth=0, zorder=3)
# Plot bottom half of inclined plane.
ax.plot_surface(X2, Y3, Z3, color='blue', alpha=.5, linewidth=0, zorder=-1)
ax.set_xlim(-10., 10.)
ax.set_ylim(-10., 10.)
ax.set_zlim(-10., 10.)
plt.show()
【问题讨论】:
标签: python matplotlib 3d plane