如何在不使用MeshGrid的情况下绘制表面

时间:2018-12-28 00:16:56

标签: python matplotlib

如何绘制下面表格中的数据表面。

第1列-X;第2栏-Y;第3列-Z;

在下面的示例中,X有4个独特点,Y有3个独特点,但是我无法预测这一点,因此每次都必须分析数据以确定如何将列重塑为网格。我可以按原样绘制点吗? (坐标列表。)

[[0.         0.         0.        ]
 [0.         0.5        0.6989218 ]
 [0.         1.         0.87790919]
 [0.25       0.         0.0505097 ]
 [0.25       0.5        0.7494315 ]
 [0.25       1.         0.92841889]
 [0.5        0.         0.09192357]
 [0.5        0.5        0.79084537]
 [0.5        1.         0.96983276]
 [0.75       0.         0.10310818]
 [0.75       0.5        0.80202997]
 [0.75       1.         0.98101736]
 [1.         0.         0.12209081]
 [1.         0.5        0.82101261]
 [1.         1.         1.        ]]

2 个答案:

答案 0 :(得分:1)

matplotlib.pyplot中,有scatter的3个暗度选项。像这样:

import matplotlib.pyplot as plt
plt.figure()
plt.scatter(x, y, z)
plt.show()

Here是文档。

编辑:对于3d绘图,您可以尝试使用mpl_toolkits.mplot3d库,如下所示:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Axes3D.plot_surface(X, Y, Z, *args, **kwargs)

答案 1 :(得分:1)

如果我正确理解了您的评论,则基本上是在寻找plot_trisurfdata是您的数据矩阵,我分别将第一,第二和第三列作为x,y,z数据。

您不需要为此进行任何重塑。 plot_trisurf的输入是一维数组。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# data = # your matrix here

fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection="3d")

x = data[:, 0]
y = data[:, 1]
z = data[:, 2]

ax.plot_trisurf(x,y,z)

enter image description here