1
votes

I am plotting a 3d surface with gnuplot "splot" function. The data is written in (x,y,z) format in 3 columns in a text file. When I plot the data from the file, splot connects the endpoints of the data. The surface itself is correct, but there is an additional unwanted set of parallel lines (forming an xy plane) at the bottom of the surface. So for each x, it plots a function decaying to zero symmetrically, but then +\infty and -\infty are connected together as well! That makes something like an unwanted x-axis below the graph.

I tried to set off boundaries to zero, playing with data format, etc. No luck!

1
are you sure that there is not an extraneous point at the beginning or the end of your data set? I've had that happen before with a similar effect. If that's not the case, can you post a minimal example of your data/code which reproduces the effect? Also, which version of gnuplot/platform are you usingandyras
It seems as though you want to plot a surface. Is your data written in gnuplot's griddata format? What happens if you set dgrid3d? Is the surface (approximately) correct?mgilson
@mgilson. Yes, I am plotting a surface. The data, as I mentioned, is in (x,y,z) format, with space between x-y-z; each triple in one line. But all these triples come after each other; I have not put a blank line between "blocks". I am not sure if it's because of this or no. Yes, when I try "set dgrid3d" the surface is correct but too coarse.eli
BTW, I have exported data from matlab. I well come suggestions if you have a proven way to export 3d data from matlab suited for gnuplot. In 2d I have no problem in using "dmwrite" to create pairs (x,y).eli
@andyras. I am using 4.4 version patchlevel 2. The data file is fine (except, perhaps, as I mentioned above, no blank line between blocks of data). Unfortunately the gnuplot manual is not well written. Almost no example, and lots of terminologies not defined. I just have a MNP matrix of (x,y,z)'s and want the software to put a dot in each coordinate. Do not know why it should be so difficult!eli

1 Answers

2
votes

Your problem is that your data isn't in 'grid data' format. Gnuplot sees the data and plots it as lines instead of plotting it as a surface. Unfortunately, I don't know matlab, but here's some pseudo-code which should work (although may not be the most efficient way to write the data):

 do iy=1 to ny
    do ix=1 to nx
       write gridx(ix,iy), gridy(ix,iy), data(ix,iy)
    enddo
    write blank line
 enddo

Of course, if your grids can be expressed as 1D arrays (instead of 2D as above), you can just do the following (with appropriate loops):

 write gridx(ix), gridy(iy), data(ix,iy)

Alternatively, you can use dgrid3d in gnuplot. dgrid3d interpolates non-grid data into grid data. By default, it interpolates to a 10x10 grid which as you noted is pretty coarse. You can increase this by set dgrid3d NX,NY where NX and NY are the number of points on the x and y axes respectively.

Finally, if you don't want to mess with your datafile, you might want to consider using the following awk script from the gnuplot FAQ (section 3.9):

#addblanks.awk
/^[[:blank:]]*#/ {next} # ignore comments (lines starting with #)
NF < 3 {next} # ignore lines which don't have at least 3 columns
$1 != prev {printf "\n"; prev=$1} # print blank line
{print} # print the line

Now to plot your surface:

set surface
splot "<awk -f addblanks.awk yourdatafile.dat"