3
$\begingroup$

From an experiment I got a huge 3d data set (~ 4*10^6 data points) which I display with ListPointPlot3D.

How can I improve the speed of showing the plot in the notebook or saving it with Export.

Here is my example code:

SeedRandom[1];

data = RandomReal[10, {4000000, 3}]; // AbsoluteTiming

{0.0923029, Null}

plot3d = ListPointPlot3D[data, PlotStyle -> PointSize -> Tiny, Boxed -> True, 
  Axes -> True, AxesLabel -> {"x", "y", "z"}, ViewProjection -> "Orthographic", 
  ViewPoint -> {2, -2.4, 2}, AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
  ColorFunction -> Function[{x, y, z}, Hue[x]]]; // AbsoluteTiming

{56.4218, Null}

Export[FileNameJoin@{$UserBaseDirectory, "plot3d.bmp"}, plot3d, "BMP"]; // AbsoluteTiming

{1255.23, Null}

Export[FileNameJoin@{$UserBaseDirectory, "plot3d.png"}, plot3d, "PNG"]; // AbsoluteTiming

{2126.69, Null}
$\endgroup$
2
  • 2
    $\begingroup$ do you really need all the points? If you do like ListPointPlot3D[RandomSample[data, 10000]] you will often get what you need and much faster. $\endgroup$
    – george2079
    Oct 19, 2017 at 19:59
  • $\begingroup$ @george2079: Yes I need to see all the points, at least the projection which the 3d plot gives. The whole point distribution can be very different from the view of a subset of only 10000 points. $\endgroup$
    – mrz
    Oct 19, 2017 at 20:31

1 Answer 1

4
$\begingroup$

Graphics3D using Point with VertexColors is much faster for producing the graphics:

 data = RandomReal[10, {4000000, 3}]; // AbsoluteTiming

(g3d = Graphics3D[{PointSize[Tiny], 
      Point[data, VertexColors -> (Hue /@ Rescale[data[[All, 1]]])]}, 
     Boxed -> True, Axes -> True, AxesLabel -> {"x", "y", "z"}, 
     ViewPoint -> {2, -2.4, 2}, 
     AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}]; ) // AbsoluteTiming // First

0.131143

 g3d

enter image description here

With a smaller dataset with 400,000 points ListPointPlot3D takes 7.025276 seconds.

Also, using the File >> Save Selection As route is much faster than using Export.

$\endgroup$
3
  • $\begingroup$ This is impressing: why is Graphics so much faster then ListPointPlot3D? $\endgroup$
    – mrz
    Oct 19, 2017 at 20:29
  • 1
    $\begingroup$ @mrz, I guess it is because it avoids overhead that *Plot and *Chart routines have to incur before they eventually invoke Graphics. $\endgroup$
    – kglr
    Oct 19, 2017 at 20:52
  • $\begingroup$ For File >> Save Selection As it is necessary to display the graphics in the notebook, which takes time. When I only want to save the plot there is probably no other command than Export? $\endgroup$
    – mrz
    Oct 20, 2017 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.