Search code examples
plotgnuploterrorbar

Generating 3D plot with error bars in Gnuplot


I have a dataset of the form

x,y,z,zerr

and want to generate a three dimensional plot of it including error bars on the values for z. So what I want is a plot like

splot "datafile.dat" using 1:2:3

which gives a regular 3D plot, but it should also include error bars. I have tried using

splot "datafile.dat" using 1:2:3:4 with errorbars

but this only generates the same plot again, not showing any error bars. Is there a way to do this in Gnuplot? If no, is there a way to do it in Python using matplotlib? If so, I might be using it instead.


Solution

  • Gnuplot does have a 3D plot style zerror that includes error ranges drawn as a shaded region rather than individual bars. Otherwise you would have to construct the points, lines, and error bars in separate plot clauses. Note that the input data specification for 3D vectors is x y z delta-x delta-y delta-z Here is a figure that shows all of these. I have forced the x values to either 0 or 1 for the purpose of separating the zerror variant from the others.

    set view 60, 120
    set xyplane at 0
    set grid x y z vertical linewidth 1
    set yrange [200:500]
    set xrange [1.5 : 0]
    set style fill transparent solid 0.25
    
    set style arrow 1 heads size screen 0.005, 90
    set style arrow 1 lc "blue" lw 1.5
    
    splot 'DATA' using (0):2:3:4 with zerror title "with zerror", \
          '' using (1):2:3 with lines title "with lines", \
          '' using (1):2:3 with points pt 7 lc "black" title "with points", \
          '' using (1):2:($3-$4):(0):(0):(2.*$4) with vector as 1 title "with vectors"
    

    enter image description here