I know there are lots of information about this on stack exchange!

Data interpolation and ListContourPlot

InterpolationOrder for ContourPlot

Unfortunately I was not able to find a proper way to deal with my issue.

I have a Volumetric data which I read from a gaussian Cube file and I can easily Plot it using ListContourPlot3D but the plot is not smooth and I can not use the InterpolationOrder in ListContourPlot3D. I tried interpolating the data and using SmoothKernelDistribution, This only works for a data [x,y] Dimension not [x,y,z]. Even then it's super slow though I only need to plot the data range of [-0.2,0.2] so probably I can cut some data and speed up.

My volumetric data is at dimensions [40,40,40], it can have some mixed volumetric shapes, as below. I have attached it as a wdx file it's the Transpose[cubedata, {3, 2, 1}, so it what would be plotted and can have shapes as below.

enter image description here enter image description here enter image description here


1 Answer 1


A volume of 40x40x40 is small enough that you can do all kinds of things with it. One easy method is to interpolate the volume yourself with a higher interpolation order

data = Import["countour.wdx"];
ip = ListInterpolation[data, InterpolationOrder -> 3];
ContourPlot3D[ip[x, y, z], {x, 15, 25}, {y, 15, 25}, {z, 15, 25}]

This already smooths your volume

Mathematica graphics

Another way from there is to resample parts of the volume from the interpolation function with a higher resolution and apply an additional smoothing filter. But this is for you to decide.


Is there anyway to still speed up the process? maybe cut the data based on my contours. I need to automate the script to work for hundreds of cube files!

Yes, there is. When we look on your data

Image[data[[10]]] // ImageAdjust

Mathematica graphics

we see, that it is pretty smooth. I would not smooth it further artificially beyond what's happening during interpolation anyway. Therefore, let me give two additional advices:

Tune the parameters for the approach I have given

This includes to verify that an interpolation order of 3 is probably not required. Order 2 will be enough and an interpolation function with decreased order will be faster.

More important, you should specify PlotPoints and MaxRecursion of your ContourPlot3D call so that it is smooth enough, but does not take unnecessary long.

Below you will find an animation that shows you the effect of both parameters. I suggest to use a recursion depth of 1 and use as many plot points as you can live with

enter image description here

Return to ListContourPlot3D with a prior resampling

Another way is to restrict your data (you can do that with the first approach too!), because it seems to me that the fun is happening in the center of your volume.

Then you can use ArrayResample to create a higher resolution and in the very same step ensure that the new volume is smooth by adjusting the resampling method. In the easiest case this looks like

 ArrayResample[data[[10 ;; 30, 10 ;; 30, 10 ;; 30]], {50, 50, 50}, 
  Resampling -> "Gaussian"],
 Contours -> {0.01}

Mathematica graphics

  • $\begingroup$ Is there anyway to still speed up the process? maybe cut the data based on my contours. I need to automate the script to work for hundreds of cube files! $\endgroup$ Sep 8, 2015 at 21:01
  • $\begingroup$ @RaymondGhaffarianShirazi I have added some further information to the end of my answer. $\endgroup$
    – halirutan
    Sep 8, 2015 at 21:45
  • $\begingroup$ I get a small issue with scale, I have updated my post, thanks for your help. $\endgroup$ Sep 8, 2015 at 22:43
  • $\begingroup$ Sorry I fixed that, I guess I had to just cheng 10;;30 to 1;;40 $\endgroup$ Sep 8, 2015 at 22:58
  • $\begingroup$ @RaymondGhaffarianShirazi The [[10;;40]] operator just selects the center of your volume. If you like to use the complete volume, then you can just use data without everything. You should probably resample than to more than {50,50,50}.. $\endgroup$
    – halirutan
    Sep 8, 2015 at 23: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.