10,000+ Point 3D Scatter Plots in Python (with Quick Rendering)
Asked Answered
G

1

9

Performance-wise, the following code snippet works perfectly fine for me when plotting in mayavi.

import numpy as np
from mayavi import mlab

n = 5000
x = np.random.rand(n)
y = np.random.rand(n)
z = np.random.rand(n)
s = np.sin(x)**2 + np.cos(y)

mlab.points3d(x, y, z, s, colormap="RdYlBu", scale_factor=0.02, scale_mode='none')

But mayavi begins to choke once n >= 10000. The analogous 3d plotting routine in matplotlib, (Axes3D.scatter) similarly struggles with data sets of this size (why I started looking into mayavi in the first place).

First, is there something in mayavi (trivial or nontrivial) that I am missing that would make 10,000+ point scatter plots much easier to render?

Second, if the answer above is no, what other options (either in mayavi or a different python package) do I have to plot datasets of this magnitude?

I tagged ParaView simply to add that rendering my data in ParaView goes super smoothly, leading me to believe that I am not trying to do anything unreasonable.

Update:

Specifying the mode as a 2D glyph goes a long way towards speeding things up. E.g.

mlab.points3d(x, y, z, s, colormap="RdYlBu", scale_factor=0.02,
              scale_mode='none', mode='2dcross')

can easily support up to 100,000 points

enter image description here

It would still be nice if anyone could add some info about how to speed up the rendering of 3D glyphs.

Graduate answered 15/8, 2016 at 19:49 Comment(0)
F
5

PyQtGraph is a much more performant plotting package, although not as "beautiful" as matplotlib or mayavi. It is made for number crunching and should therefore easily render points in the order of ten thousands.

As for mayavi and matplotlib: I think with that number of points you've reached what is possible with those packages.

Edit: VisPy seems to be the successor to PyQtGraph and some other visualization packages. Might be a bit overkill, but it can display a few hundred thousand points easily by offloading computation to the GPU.

Flash answered 29/8, 2016 at 11:25 Comment(1)
Thanks for resuscitating this question! While VisPy does seem to be a very powerful visualization package, at first glance it's API is more complicated than I'm used to for python packages and it seems particularly geared for dynamic plotting/rendering. Anyhow, I'll see if it suits my purposes in the coming days, thanks!Graduate

© 2022 - 2024 — McMap. All rights reserved.