相关疑难解决方法(0)

在 Python 中绘制 3D 立方体并在 3D 上绘制线

我知道,对于那些熟悉 Python 的人来说这是小菜一碟的问题。

我有一个 Excel 文件,它看起来像这样:

1 7 5 8 2 4 6 3

1 7 4 6 8 2 5 3

6 1 5 2 8 3 7 4

我的目的是用Python画一个立方体,并根据这些数字的顺序画一条线。注意:数组中没有大于8的数字。

我可以用图片更好地解释。

在此输入图像描述

第一步:

在此输入图像描述

第二步

在此输入图像描述

最后一步:

在此输入图像描述

我需要打印 Excel 中每一行的 3D 立方体的最终版本

我的解决方法

import numpy as np 
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
import matplotlib.pyplot as plt
 
df = pd.read_csv("uniquesolutions.csv",header=None,sep='\t')
myArray = df.values

points = solutionsarray

def connectpoints(x,y,p1,p2):
   x1, x2 = x[p1], x[p2]
   y1, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib cube

5
推荐指数
1
解决办法
9886
查看次数

Python 3d金字塔

我是3D绘图的新手。我只想从5个点中构建一个金字塔并切入一个平面。我的问题是我不知道该如何填补问题。

points = np.array([[-1, -1, -1],
                   [1, -1, -1 ],
                    [1, 1, -1],
                   [-1, 1, -1],
                   [0, 0 , 1]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = [-1,1]

X, Y = np.meshgrid(r, r)

ax.plot_surface(X,Y,-1, alpha=0.5)
ax.plot_surface(X,Y,0.5, alpha=0.5,  facecolors='r')


ax.scatter3D(points[:, 0], points[:, 1], points[:, 2])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

python matplotlib mplot3d

3
推荐指数
1
解决办法
3135
查看次数

标签 统计

matplotlib ×2

python ×2

cube ×1

mplot3d ×1