Abolfazl
Abolfazl

Reputation: 453

Plot 3 dimensional unequal length of data

I am new in gnuplot so excuse me if it looks simple. I have a data file like below and I want to draw a diagram like this:

enter image description here

t       x = 0.00        0.20        0.40        0.60        0.80        1.00
0.00    0.000000    0.640000    0.960000    0.960000    0.640000    0.000000
0.02    0.000000    0.480000    0.800000    0.800000    0.480000    0.000000
0.04    0.000000    0.400000    0.640000    0.640000    0.400000    0.000000
0.06    0.000000    0.320000    0.520000    0.520000    0.320000    0.000000
0.08    0.000000    0.260000    0.420000    0.420000    0.260000    0.000000
0.10    0.000000    0.210000    0.340000    0.340000    0.210000    0.000000
0.12    0.000000    0.170000    0.275000    0.275000    0.170000    0.000000
0.14    0.000000    0.137500    0.222500    0.222500    0.137500    0.000000
0.16    0.000000    0.111250    0.180000    0.180000    0.111250    0.000000
0.18    0.000000    0.090000    0.145625    0.145625    0.090000    0.000000
0.20    0.000000    0.072813    0.117813    0.117813    0.072813    0.000000

GNU octave equivalent command is something like this:

mesh(tplot,xplot,ttplot);

Upvotes: 1

Views: 120

Answers (1)

Thor
Thor

Reputation: 47099

Well as with many things, it is simple if you know how. This is straighforward to plot if you remove the x = and the t from the data file, e.g.:

0           0.00        0.20        0.40        0.60        0.80        1.00
0.00    0.000000    0.640000    0.960000    0.960000    0.640000    0.000000
0.02    0.000000    0.480000    0.800000    0.800000    0.480000    0.000000
0.04    0.000000    0.400000    0.640000    0.640000    0.400000    0.000000
0.06    0.000000    0.320000    0.520000    0.520000    0.320000    0.000000
0.08    0.000000    0.260000    0.420000    0.420000    0.260000    0.000000
0.10    0.000000    0.210000    0.340000    0.340000    0.210000    0.000000
0.12    0.000000    0.170000    0.275000    0.275000    0.170000    0.000000
0.14    0.000000    0.137500    0.222500    0.222500    0.137500    0.000000
0.16    0.000000    0.111250    0.180000    0.180000    0.111250    0.000000
0.18    0.000000    0.090000    0.145625    0.145625    0.090000    0.000000
0.20    0.000000    0.072813    0.117813    0.117813    0.072813    0.000000

Then the data can be interpreted as a "non-uniform" matrix, although it is uniform. This is useful as it reads the first row and first column correctly. See help matrix and help matrix nonuniform for more. For example:

echo 'splot "data" nonuniform matrix with lines' | gnuplot --persist

Gives me:

Plot of data matrix

To make it similar to the output produced by the GNU Octave mesh command, do something like this:

set xlabel "x"
set ylabel "t"
set zlabel "u"
set view 20,210
set border 4095 lw 2
set hidden3d
set xyplane 0
set autoscale fix
set nokey
set notics
splot "data" nonuniform matrix lt -1 lw 2 with lines

Which results in:

Plot that is more similar to the original

Upvotes: 3

Related Questions