plotgnuplotstreamline

Gnuplot , pm3d with contour lines


i am 3d plotting a matrix with some values, and i need to add contour lines to the plot, is there a simple gnuplot command to do this?

I tried the command: "set contour base" but only 1 line came up, i think it should be many lines. See matlab picture

When i plot it in gnuplot i only get 1 contour line in the top left corner.But everything else is correct.

My goal is to get it to look like in matlab like this Matlabplot

I also found this example: see link in comments (dont have enough rep), but i dont understand where i should put in the data values from test.txt

test.txt

test.txt

gnuplot commands

set view map
set yrange [0:30]
set xrange [0:30]
set dgrid3d 100,100,4
set contour base
splot 'test.txt' u 1:2:3 w pm3d

Solution

  • What you are missing is to tell gnuplot where to put the contours. This is done via the set cntrparam levels incr -0.3,0.1,0.5 command which means: start at -0.3 and trace a contour every o.1 up to 0.5.

    AFAIK if you want to make contours all black, you have to save the contour lines in a temporary file (here contour.txt).

    So your script would be

    reset
    set contour
    unset surface
    set cntrparam levels incr -0.3,0.1,0.5
    
    set view map
    set xrange [0:30]
    set yrange [0:30]
    
    set dgrid3d 100,100,4
    
    set table "contour.txt"
    splot 'test.txt'
    unset table
    
    unset contour
    set surface
    set table "dgrid.txt"
    splot 'test.txt'
    unset table
    
    reset
    set pm3d map
    unset key
    set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
    set autoscale fix
    set grid
    
    splot 'dgrid.txt' w pm3d, 'contour.txt' w l lc rgb "black"
    

    which gives you this:

    here

    Note:

    you can get rid of interpolation file (dgrid.txt) if you format a bit your datafile by leaving a blank line after each row (i.e. every 30 datapoints) because they are already mesh-ordered.

    This could be done also with a awk script. But I'm too lazy to look into it...

    The rest will remain the same and will work as expected.

    here is how it should look like :

    In which case the script would simply become:

    set pm3d map impl
    set contour
    set style increment user
    do for [i=1:18] { set style line i lc rgb "black"}
    set cntrparam levels incr -0.3,0.1,0.5
    set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
    set autoscale fix
    splot 'test.txt' w pm3d notitle
    

    with no need of ntermediate file and with better contour since data in not interpolate by gridded:

    enter image description here