0
votes

I am new to gnuplot and trying to plot a contour plot with xyz data which is in text file. I have tried many different methods but it gives only blank plot.

DATA is in Google Drive : https://drive.google.com/open?id=1x-NAD9Vs8wyv9QbDgjcaT9SujHlHChAd

set contour base
set pm3d
unset surface
set view map
set xrange [1000:4000]
set yrange [0.2:0.395]
set zrange [0:40000]
splot "relax.txt" using 1:2:3

Followed error message: Warning: Single isoline (scan) is not enough for a pm3d plot. Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.

1

1 Answers

0
votes

The problem is that gnuplot requires an empty line after each (matrix) row (e.g. when column 1 value changes). So you can insert the empty lines yourself manually or with an external tool or let gnuplot do this. You plot your data into a dummy-table (a datablock) and then you print it to another datablock and insert an empty line when the value of column 1 changes. A bit cumbersome but it works. Requires gnuplot >=5.2.

Code:

### contour plot, addding empty lines to raw data
reset session
set contour base
set pm3d
set cntrparam level 10
unset surface
set view map
set size 0.9,0.9    # shrink the size a little otherwise colorbar numbers will be outside canvas

### insert empty lines everytime when column 1 changes its value

set table $Dummy                                        # initialize a table (datablock) named $Dummy
    plot "relax.txt" u 1:2:3 with table                 # plot datafile into a datablock $Dummy
unset table                                             # close the table
set print $Data                                         # set print output to datablock $Data
    check=""                                            # initialize your comparison variable to empty string
    do for [i=1:|$Dummy|] {                             # loop the datablock $Dummy by lines
        if (check ne word($Dummy[i],1)) { print "\n" }  # comparison: if values are not equal insert a line
        print $Dummy[i]                                 # print current line to datablock $Data
        check = word($Dummy[i],1)                       # assign latest value to variable "check"
    }
set print                                               # close the datablock $Data

splot $Data u 1:2:3 w l notitle
### end of code

Result:

enter image description here