在我目前的项目中,我想用pyplot绘制一个3D形状。这是相对简单的:
复杂性来自于这样一个事实,即我希望图形以类似于此示例的直2D图形显示:
也就是说,删除3D轴和刻度、网格线,并将所有内容包裹在平面2D边界中。用Pyplot可以做到这一点吗?你可以找到我的代码来生成下面的两个图:
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
x = np.asarray([0,1,1.5,0.5,0])
y = np.asarray([0,0,0.5,0.5,0])
# Plot 2D projection of cube
plt.plot(x,y,color='k')
plt.plot(x,y+1,color='k')
plt.plot([0,0],[0,1],color='k')
plt.plot([1,1],[0,1],color='k')
plt.plot([1.5,1.5],[0.5,1.5],color='k')
plt.plot([0.5,0.5],[0.5,1.5],color='k')
plt.title("2D projection of cube")
plt.axis('equal')
plt.tick_params(left=False,
bottom=False,
labelleft=False,
labelbottom=False)
# Now try the same thing in 3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.asarray([0,1,1,0,0])
y = np.asarray([0,0,1,1,0])
# Plot 2D projection of cube
ax.plot3D(x,y,np.zeros(5),color='k')
ax.plot3D(x,y,np.ones(5),color='k')
ax.plot3D([0,0],[0,0],[0,1],color='k')
ax.plot3D([0,0],[1,1],[0,1],color='k')
ax.plot3D([1,1],[0,0],[0,1],color='k')
ax.plot3D([1,1],[1,1],[0,1],color='k')
plt.title("3D projection of cube")
2条答案
按热度按时间toe950271#
添加这些行:
输出:
2hh7jdfx2#
以下方法: