有什么简单的方法可以在 Python 中绘制我可以旋转的 3d 散点图? [英] Any easy way to plot a 3d scatter in Python that I can rotate around?

查看:58
本文介绍了有什么简单的方法可以在 Python 中绘制我可以旋转的 3d 散点图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用 matplotlib 绘制 3d 散点图,虽然它完成了工作,但我似乎无法找到一种方法来旋转它以更好地查看我的数据.

Currently I'm using matplotlib to plot a 3d scatter and while it gets the job done, I can't seem to find a way to rotate it to see my data better.

这是一个例子:

import pylab as p
import mpl_toolkits.mplot3d.axes3d as p3

#data is an ndarray with the necessary data and colors is an ndarray with
#'b', 'g' and 'r' to paint each point according to its class

...

fig=p.figure()
ax = p3.Axes3D(fig)
ax.scatter(data[:,0], data[:,2], data[:,3], c=colors)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
fig.add_axes(ax)
p.show()

我想要一个解决方案,让我可以在执行期间执行此操作,但只要我可以旋转它并且它很短/快速,我就可以接受.

I'd like a solution that lets me do it during execution time but as long as I can rotate it and it's short/quick I'm fine with it.

以下是对虹膜数据集应用 PCA 后生成的图的比较:
1. mayavi

2.matplotlib

Here's a comparison of the plots produced after applying a PCA to the iris dataset:
1. mayavi

2. matplotlib

Mayavi 使数据可视化更容易,但 MatPlotLib 看起来更专业.Matplotlib 也更轻.

Mayavi makes it easier to visualize the data, but MatPlotLib looks more professional. Matplotlib is also lighter.

推荐答案

使用 mayavi,您可以创建这样的一个情节与

Using mayavi, you can create such a plot with

import enthought.mayavi.mlab as mylab
import numpy as np
x, y, z, value = np.random.random((4, 40))
mylab.points3d(x, y, z, value)
mylab.show()

GUI 允许通过单击和拖动进行旋转,并通过右键单击和拖动进行放大/缩小.

The GUI allows rotation via clicking-and-dragging, and zooming in/out via right-clicking-and-dragging.

这篇关于有什么简单的方法可以在 Python 中绘制我可以旋转的 3d 散点图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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