3-Dimensional Plot in GnuPlot where color is a fourth column in my data file?

前端 未结 1 1488
半阙折子戏
半阙折子戏 2020-12-17 23:08

I have a datafile 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


        
相关标签:
1条回答
  • 2020-12-17 23:48

    Using only pm3d you can use a fourth column to select a color independent of the z-value. Together with dgrid3d this is not directly possible, because the gridding is not performed on the color column.

    You can use a workaround: First you plot the gridded z-value to one file, then the gridded color values to a second file and as last point you disable dgrid3d, merge the two temporary files on-the-fly and plot 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

    Note, that paste is a command line tool for Unix-like operation systems. For a similar solution for windows, you can e.g. write a small Python script paste.py (see my answer to Get ratio from 2 files in gnuplot for a possible implementation). Then you must run the wgnuplot_pipes.exe binary file and the splot command becomes

    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 available via the PATH environment variable.

    0 讨论(0)
提交回复
热议问题