python - 如何在 matplotlib 中制作 3D 散点图

标签 python 3d matplotlib plot scatter-plot

我目前有一个 nx3 矩阵数组。我想将三列绘制为三个轴。 我怎样才能做到这一点?

我用谷歌搜索过,有人建议使用 Matlab,但我真的很难理解它。我还需要它是一个散点图。

有人可以教我吗?

最佳答案

您可以使用 matplotlib为了这。 matplotlib 有一个 mplot3d模块,将完全按照您的意愿行事。

import matplotlib.pyplot as plt
import random

fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(projection='3d')

sequence_containing_x_vals = list(range(0, 100))
sequence_containing_y_vals = list(range(0, 100))
sequence_containing_z_vals = list(range(0, 100))

random.shuffle(sequence_containing_x_vals)
random.shuffle(sequence_containing_y_vals)
random.shuffle(sequence_containing_z_vals)

ax.scatter(sequence_containing_x_vals, sequence_containing_y_vals, sequence_containing_z_vals)
plt.show()

上面的代码生成如下图:

enter image description here

关于python - 如何在 matplotlib 中制作 3D 散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1985856/

相关文章:

python - 将列级别由内而外

math - 将点积夹在四元数的 Slerp 中

c - 在同一个 OpenGL 窗口中绘制 2D 和 3D

python - 绘制数组中特定范围的值 Pyplot

python - 使用 matplotlib.collection.LineCollection 时发生内存泄漏

python-3.x - 如何在极坐标图中弯曲文本?

python - 写入 csv 时如何保留空值

python - siginterrupt() 只适用于第一个信号? (Python)

python - Pandas - 计算总给定范围的百分比

c++ - Opengl 在 2d 或 3d 中显示顶点