Search code examples
gnuplot

GNUPLOT: using splot with palette option, reproduce smooth colour changes


I generate a .txt file containing four colums: X, Y and Z coordinates, as well as a scalar variable. The first three values in each row describes a unitary vector in 3D, to which the scalar value is associated.

I would like to plot the results as a coloured spherical surface. I cannot readily use pm3D as the data are in not in matrix format, that is, no blank space after jumps in the X coordinates. Moreover, there are hardly two identical X coordinates.

The best I could do is to use splot, with the palette option, which I understand would use the data in the 4th column to assign colors to each point.

Data to be plotted are saved in "star.txt", a simple text file with 4 columns, and up to 10.000 rows.

The Gnuplot script looks like

    set terminal wxt size 800,800
    set mapping cartesian
    set view equal xyz
    set xlabel 'x'
    set ylabel 'y'
    set zlabel 'z'
    splot "star.txt" palette pointtype 7
    pause -1

It would be great if there were a way to get smooth colour changes on the surface. At the moment it is not trivial to understand where a colour area is. Also, one could see through the points to the surface that is actually farther from the viewer.

Any suggestion would be highly appreciated.enter image description here


Solution

  • To the extent that the colors of adjacent points are due to one being on the front surface and one being on the back surface, you can improve the effect by adding a command

      set hidden3d
    

    This will sort the points on distance from the viewer so that points on the front surface will be drawn last and therefore not be occluded by points from the back surface. It would be possible to make the coloring semi-transparent so that you could "see through" it, but that would make distinguishing front and back harder rather than easier.

    Follow-up

    The problem is not interpolation. The problem is that you are plotting points, and each point is some single color. It is not clear exactly what you want to draw ideally. A perfect sphere? A surface fit to the points, which may or may not be spherical? Is there a coloring function that you applied to the points, or are the points themselves defining the desired color?

    1) If you are asking how to draw a perfect colored sphere, see for example the answer to this recent question: gnuplot: Plotting a function on the surface of a sphere Because you ask specifically about interpolation, I will note that the coloring shown in that answer would be smoother if you increased the level of interpolation:

      set pm3d interpolate 3,3    # your choice of values > 1
    

    2) If you are asking how to color an arbitrary surface according to some scheme represented by values at known points, I think the answer is that the current stable gnuplot release version (5.2) cannot do that, but the development version (5.3) can. See answer to this previous question Heatmap of points in a volume and in particular the online demo http://gnuplot.sourceforge.net/demo_5.3/voxel.html. I reproduce the final plot of that demo below. enter image description here