Gnuplot, how to invert x with y while plotting fil

2019-08-03 17:08发布

问题:

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

回答1:

gnuplot> plot "./data.txt" using 2:1 with lp

"using" will allow you to select arbitrary columns from your data.