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
It would still be nice if anyone could add some info about how to speed up the rendering of 3D glyphs.
Generally 3D scatter plot is created by using ax. scatter3D() the function of the matplotlib library which accepts a data sets of X, Y and Z to create the plot while the rest of the attributes of the function are the same as that of two dimensional scatter plot.
Interesting. As Jonathan Dursi's answer mentions, 20 million points is achievable with Matplotlib, but with some constraints (raster output,…).
Create ChartAfter 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With