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

问题描述

目前我使用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看起来更专业。


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

推荐答案

使用,您可以使用

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.

这篇关于任何简单的方法来绘制一个3d分散的Python,我可以旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:44