GNU Plot: Plotting x, y, z values stored as one column - gnuplot

With GNU Plot, I normally process x, y, z data in three separate columns:
x1, y1, z1
x2, y1, z2
...
...
xn, yn, zn
and I used splot 'filename.ext' with lines to quickly get the a 3D plot
Due to our new system requirements, we have to store data in the following form:
x1
y1
z1
x2
y2
z2
.
.
xn
yn
zn
I already written a simple code in C# to transform our results into 3 columns for easy viewing in GNU Plot.
My question is, if the data is now only a one dimensional array, is there a way to plot this in GNU Plot directly without having my program to re-saved our results as a 3 columns results?
Thank you.
Regards,
ikel
Additional info: I am running on Win7, 64 bit, and using the Win binaries of GNU Plot. Apparently, I don't have paste, sed and popen (see discussion below).

I don't know how to make Gnuplot interpret the input as groups of three, but if your version of Gnuplot supports popen, you can join the lines on the fly with e.g. paste or sed:
splot '< paste - - - < filename.ext' with lines
Or:
splot '< sed "N; N; s/\n/ /g" filename.ext' with lines

Related

gnuplot arrow coordinates (x,y) error columns

I'm new in gnuplot and my aim is to plot arrows between each data coordinate. My ".dat" file has only two columns, separated by a single tab, where the first is the X and the second is the Y component. The head should be set in the next coordinate.
582.761 -326.288
574.806 -327.915
My command was:
plot 'file.dat' using 1:2 with vectors head filled
I only can obtain the following error message:
Not enough columns for this style
Sorry for the dumb question, but I couldn't understand neither the documentation nor other questions in the same subject.
If you check help vectors you will see that with vectors plotting style requires 4 values.
And if I understand your question correctly I guess you want to plot arrows from one data line to the next data line, correct?
By the expression (x0=x1,x1=$1,x0) you keep the previous x value in x0 and the current value in x1, but you're plotting x0. Same for y0 and y1. And (x1-x0) and (y1-y0) are simply the delta x and delta y values which you need for the with vectors plotting style.
Code:
### vectors from data line to the next
reset session
$Data <<EOD
1 1
2 2
3 5
2 4
1 2
EOD
x1=y1=NaN
plot $Data u (x0=x1,x1=$1,x0):(y0=y1,y1=$2,y0):(x1-x0):(y1-y0) w vectors head filled notitle
### end of code
Result:

How to do a 3D line plot in gnuplot using x, y, z data contained in a text file?

I have a text file (named lorenz-phase.txt, as you can probably guess it is the solution to the Lorenz equations) that contains data of the format:
1 1 1
1.01257 1.25992 0.984891
1.04882 1.524 0.973114
1.10721 1.79831 0.965159
1.18687 2.08854 0.961737
and so forth, where the first column is my x values, the second column is my y values and the third column is my z values. I would like to plot a 3D line plot of this data using gnuplot. Is this possible and how is it done? Google has not given me an answer on this front, as the plots I could find were when a parametric function describes the plot.
Use the splot command for 3d plots, and with lines for lines:
splot "lorenz-phase.txt" using 1:2:3 with lines
My first google result with keywords gnuplot 3d line is this one.

colour contour plot from a sequential xy file (datablocks)

I am trying to produce a colour contour plot (the coloured projection of a surface or a "map") from a file that has the following format:
y1 z1 #first block
y1 z2
y1 z3
....
y1 zn
<blank line>
y2 z1 #second block
y2 z2
y2 z3
....
y2 zn
<blank line>
y3 z1
y3 z2
y3 z3
....
y3 zn
etc
Hence if you took the second column of each datablock, you turned it into a line (instead of column) and you stuck them one on top of the other, you would get your traditional matrix plot.
Is there a way to plot this thing (or to take the z columns, make them into lines, stack them and plot them)?
I have been looking into splot, set view map.
So your xvalues are uniformly distributed? Do something like this
set view map
splot "data" u (column(-1)):($1):($2) w pm3d
If you can define your xvalues, use
xval(x)=1.+0.5*x #or whatever
splot "data" u (xval(column(-1))):($1):($2) w pm3d

Rotating a plot in gnuplot

1-How can I rotate my plot so y would be the new x axis and vice versa?
2- Change the maximum value of y axis from 60 to 100.
The plot is created by this script in the terminal :
set palette grey
plot 'color_map.dat' matrix with image
You can exchange the x and y axes with the using modifier. (Just like for ordinary plots, except that for matrix data, columns 1 and 2 are not in your data file, but are inferred.)
plot 'color_map.dat' matrix using 2:1:3 with image
If you actually just want to change the maximum value on the y (new x) axis, you would use set xrange[:100]. But it sounds like you might actually want to scale the data itself, in which case you could use
plot 'color_map.dat' matrix using ($2/60.*100):1:3 with image
Try help plot matrix for more details.

Gnuplot, how to invert x with y while plotting file data?

I have a 'data.txt' file containing two columns and N rows, corresponding to N points, e.g.
0.2 0.3
0.4 0.6
0.1 0.7
0.9 0.6
If I use Gnuplot to plot data from this file, using the command
plot "datafile.txt" with lp
it plots every point in the default form (X, Y), that is Gnuplot interprets the first column as all the X values, and the second column as all the Y values.
I would like to invert the meaning of X and Y. I would like to set Gnuplot this command: "Take the first column as Y, and the second column as X"
And so I would like Gnuplot to take all the data from file like (Y,X) and plot them as (X,Y).
How could I do this?
Thanx
gnuplot> plot "./data.txt" using 2:1 with lp
"using" will allow you to select arbitrary columns from your data.

Resources