2

I've been unable to find a way of producing the plot described in the title, does anyone know how to do this if it's possible? I'd like to plot a surface from a function, and plot points from a file, and have lines drawn between the points and the surface. The link below is an image that contains an example of what I'd like to do, taken from a stackoverflow question for an identical task (but for a different plotting program).

Graph example

luk2302
  • 55,258
  • 23
  • 97
  • 137
Cog77
  • 23
  • 5
  • I could write something that loops through the points in the data file, and calculates the z value corresponding to (x,y) of each point using the equation for the surface plot. Then create another file which contains pairs of coordinates (for the data point and corresponding surface point), and plot this as a third data series. I will do this if there is no fast solution in gnuplot, but I would be interested if anyone does know of a gnuplot method. – Cog77 May 02 '15 at 12:11

1 Answers1

2

You can do the calculations inside gnuplot's using statement. For the lines I use the vectors plotting style, and with arrowstyle variable (or linecolor variable) you can select different colors depending on the dz value:

set style arrow 1 linecolor rgb 'red' nohead
set style arrow 2 linecolor rgb 'green' nohead

splot f(x,y) with lines, \
    'points.dat' using 1:2:(f($1,$2)):(0):(0):(dz=$3-f($1,$2)):(dz < 0 ? 1 : 2) with vectors arrowstyle variable,\
    '' using 1:2:3 with points pt 7 ps 5

I'm not sure, which this gives problems with gnuplot 4.6. For your case you can also use linecolor variable or linecolor rgb variable to change the color of the vertical lines:

splot f(x,y) with lines, \
    'points.dat' using 1:2:(f($1,$2)):(0):(0):(dz=$3-f($1,$2)):(dz < 0 ? 0xff0000 : 0x00ff00) with vectors nohead linecolor rgb variable lw 5,\
    '' using 1:2:3 with points pt 7 ps 5
Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Great, thank you. I have a question about getting this to work on a particular gnuplot version though. I'm putting commands into a script and calling it from gnuplot on Windows 7. It works perfectly in gnuplot v5. However, in v4.6 the `$` symbols have to be changed to `$$`. After that change I get an error "arrowstyle 0 not found", so I assume that there is some problem with how it is parsing the conditional variable that determines the arrow style. Any idea how to correct that please? – Cog77 May 03 '15 at 11:01
  • Even if I replace `(dz < 0 ? 1 : 2)` with `4` and add a fourth column to the data file (containing either the number "1" or "2"), I still get the "arrowstyle 0 not found" error message. Seems like gnuplot v4.6 patchlevel 3 is not liking `arrowstyle variable`. I'll just use v5 for this graph as it should be a one off. – Cog77 May 03 '15 at 12:33
  • Using `linecolor rgb variable` works even in v4.6. Thank you so much! – Cog77 May 03 '15 at 20:49