Search code examples
gnuplot

Gnuplot - How to splot surface and points with dgrid3d


I have a .dat file that I need to plot as a surface :

functionVisu.dat
X   Y     Z
0 -3.9 1.68777
0 -4 1.7568
0 -4.1 1.81828
0 -4.2 1.87158
0 -4.3 1.91617
0 -4.4 1.9516
0 -4.5 1.97753
0 -4.6 1.99369
0 -4.7 1.99992
0 -4.8 1.99616
0 -4.9 1.98245
-0.1 -3.9 1.68277
-0.1 -4 1.75181
-0.1 -4.1 1.81328
-0.1 -4.2 1.86658
-0.1 -4.3 1.91117
-0.1 -4.4 1.94661
-0.1 -4.5 1.97253
-0.1 -4.6 1.9887
-0.1 -4.7 1.99493
-0.1 -4.8 1.99117
-0.1 -4.9 1.97746
-0.2 -3.9 1.66783
-0.2 -4 1.73687
etc

But also need to plot points on this surface, the file containing the points (pointVisu.dat) is also XYZ values. The problem is, with my actual script:

set hidden3d
set dgrid3d 50,50 qnorm 2
splot [-10:10][-10:10] "functionVisu.dat" with lines, "pointVisu.dat" with dots lw 10 lc rgb "red"
pause -1

the result I am getting is not looking as expected : result

My points are spreaded due to the dgrid3d, but I can't manage to make them appear as wanted. Also, with the use of qnorm 2, the points are under the surface function even though they are strict images of it.

Points under the surface

I can have the result I want but without using dgrid3d, which gives me a good but not aesthetic result: Wanted but bad result

How could I combinate the render of dgrid3d but with single points displaying properly ? Thanks


Solution

  • Gnuplot version 5.4.3 (Dec 2021) introduced a keyword "nogrid" that can be added to the splot command so that points are plotted individually rather being used for a grid. So if your copy of gnuplot is new enough, the answer to one of your questions is shown below (using some other data)

    set hidden3d
    set dgrid3d 25,25 
    splot "foo.dat" with lines title "gridded", \
          "foo.dat" with points nogrid pt 7 title "nogrid"
    

    enter image description here

    Fallback for older gnuplot versions

    For older gnuplot versions that do not recognize the nogrid keyword there is a work-around. Not all plot styles can be gridded, and this includes the with labels plot style. But labels can have an associated point, so you can plot a set of non-gridded points by describing them as labels with blank text:

    splot "foo.dat" using 1:2:3 with lines title "gridded", \
          "foo.dat" using 1:2:3:("") with labels point pt 7 title "nogrid"