如何在 Python 中制作 3D 散点图? [英] How to make a 3D scatter plot in Python?

查看:32
本文介绍了如何在 Python 中制作 3D 散点图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently have a nx3 matrix array. I want plot the three columns as three axis's. How can I do that?

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

I have googled and people suggested using Matlab, but I am really having a hard time with understanding it. I also need it be a scatter plot.

有人可以教我吗?

推荐答案

您可以为此使用 matplotlib.matplotlib 有一个 mplot3d 模块,可以完全满足您的需求.

You can use matplotlib for this. matplotlib has a mplot3d module that will do exactly what you want.

from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D
import random


fig = pyplot.figure()
ax = Axes3D(fig)

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)
pyplot.show()

上面的代码生成如下图:

The code above generates a figure like:

这篇关于如何在 Python 中制作 3D 散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆