Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib alternative for 3D scatter plots

I am having a hard time using Matplotlib to visualize reprojection results of my data in 3 dimensions after applying Principle components analysis or Linear discriminant analysis. After doing a scatter plot, I cannot rotate the data or change the point of view while zooming easily (Rotation axis stays the same even after you zoom, and if you zoom too much points just disappear) and every change takes one second to occur. Matplotlib is very useful but for this specific use case it starts to get very frustrating as it probably wasn't designed for such tasks. Is there an alternative to Matplotlib in Python that can handle 3d scatter plots better and where one could fluidly navigate through the cloud?

An example is shown in the next figure. I have drawn spheres around each data cluster corresponding to a specific class and colored overlapping spheres with red. Now I want to see how these sphere intersect. I think the biggest problem with Matplotlib is that it doesn't allow shifting of the whole graph with the mouse, it only allows rotation around a fixed point, which makes things very messy once you zoom a bit.

enter image description here

like image 744
Mehdi Avatar asked Jul 28 '15 10:07

Mehdi


People also ask

Can we plot 3D plots Matplotlib?

3D plotting in Matplotlib starts by enabling the utility toolkit. We can enable this toolkit by importing the mplot3d library, which comes with your standard Matplotlib installation via pip. Just be sure that your Matplotlib version is over 1.0. Now that our axes are created we can start plotting in 3D.

How do you make a 3D scatter plot?

After adding data, go to the 'Traces' section under the 'Structure' menu on the left-hand side. Choose the 'Type' of trace, then choose '3D Scatter' under '3D' chart type. Next, select 'X', 'Y' and 'Z' values from the dropdown menus. This will create a 3D scatter trace, as seen below.


1 Answers

matplotlib is not quite mature for 3d graphics : http://matplotlib.org/mpl_toolkits/mplot3d/faq.html

mplot3d was intended to allow users to create simple 3D graphs with the same “look-and-feel” as matplotlib’s 2D plots. Furthermore, users can use the same toolkit that they are already familiar with to generate both their 2D and 3D plots.

I don't think easy navigation in a 3d plot is easily doable (even 3d scaling is not possible without tweaking the lib). mplot3d was not really intended to be a full-fledged 3D graphics library in the beginning, but more a nice addition for people who needed basic 3D and who were acquainted with matplotlib 2D plot structure.

You might want to take a look at MayaVI (which is pretty good) :

MayaVi2 is a very powerful and featureful 3D graphing library. For advanced 3D scenes and excellent rendering capabilities, it is highly recomended to use MayaVi2.

Note that unlike matplotlib, MayaVI is not yet compatible with Python3 (and might not be in the foreseeable future), so you'll need a Python2 installation.

like image 89
Nihl Avatar answered Oct 31 '22 02:10

Nihl