GnuPlot 3D chart, where is the fourth column in my data file?

I have a data file that looks like this:

1 2 3 0.5 2 8 9 0.2 3 4 78 0.4 6 5 7 0.01 9 9 9 0.3 10 12 18 0.9 6 8 4 1 

I would like to make such a schedule http://2.bp.blogspot.com/-378_rAaSSVU/UzU0gnGcr9I/AAAAAAAAABnU/P1GwP9RKBkM/s1600/gnuplot.png Where the 4th column is the color.

I tried - obviously wrong, because I am not using the fourth column, but I could not find anything in the documentation:

 set dgrid3d 30,30 set view 60,45 set hidden3d dataFile='prova.dat' set palette defined (0 "blue", 0.5 "white", 1 "pink") set pm3d splot dataFile u 1:2:3 with pm3d 

Is this possible?

+6
source share
1 answer

Using only pm3d , you can use the fourth column to select a color independent of the z value. Together with dgrid3d this is not possible because the grid is not executed in the color column.

You can use a workaround: first you create a grid value z for one file, then the grid color values โ€‹โ€‹for the second file and as the last point you turn off dgrid3d , merge the two temporary files on the fly and build their values:

 set dgrid3d 30,30 dataFile='prova.dat' set table dataFile.'.grid' splot dataFile u 1:2:3 unset table set table dataFile.'.color' splot dataFile u 1:2:4 unset table set view 60,45 set hidden3d set palette defined (0 "blue", 0.5 "white", 1 "pink") set autoscale cbfix set pm3d unset dgrid3d set ticslevel 0 splot sprintf('< paste %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle 

enter image description here

Please note that paste is a command line tool for Unix-like operating systems. For a similar solution for windows, you can, for example, write a small Python script paste.py (see my answer to Get a ratio of 2 files in gnuplot for a possible implementation). Then you should run the wgnuplot_pipes.exe binary and the splot command will become

 splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle 

Of course, for this you must have python installed, and the python binary must be accessible via the PATH environment variable.

+6
source

Source: https://habr.com/ru/post/974558/


All Articles