gnuplot plot labelled data

2020-03-01 09:45发布

问题:

I am new to gnuplot and am having trouble finding the meaning of some of the commands. I want to plot a csv file where the rows are data points and the three columns represent the data label, x value and y value respectively. I want the second column on the x axis and the third column on the y axis and the first column to be the label attached to that point. Here is the data

ACB,  0.0000000,  0.0000000000
ASW,  1.0919705, -0.0864042502
CDX,  0.0000000,  0.0000000000
CEU, -0.4369415, -0.5184317277
CHB, -0.4686879,  0.7764323199
CHD,  0.0000000,  0.0000000000
CHS, -0.4141749,  0.7482543582
CLM, -0.2559306, -0.2535837629
FIN, -0.5004242, -0.2108050200
GBR, -0.4140216, -0.5132990203
GIH,  0.0000000,  0.0000000000
IBS, -0.4928541, -0.5812216372
JPT, -0.4821734,  0.7263450301
KHV,  0.0000000,  0.0000000000
LWK,  1.4515552, -0.0003996165
MKK,  0.0000000,  0.0000000000
MXL, -0.4019733, -0.0484315198
PEL,  0.0000000,  0.0000000000
PUR, -0.2165559, -0.3173440295
TSI, -0.3956957, -0.4549254002   
YRI,  1.5555644, -0.0202297606

I have tried things like

plot 'infile' using 2:2 with labels, 'infile' using 1:2

but it reports "Not enough columns for this style". I don't really know what the numbers around the colons mean, although I see them everywhere in others' code.

回答1:

You can do this with the following command:

set datafile sep ','
plot 'test.dat' u 2:3:1 w labels point offset character 0,character 1 tc rgb "blue"

Part of your confusion is probably gnuplot's shorthand notation for a lot of things. For example, in the command above, u stands for using and w stands for with and tc stands for textcolor. In general, gnuplot allows you to shorten a command to the shortest unique sequence of characters that can be used to identify it. so with can be w,wi,wit and gnuplot will recognize any of them since no other plot specifiers start with w.

The numbers after the using specifier are columns in your datafile. So here, the x position of the label is taken from the 2nd column. The y position is taken from the 3rd column. And the label text is taken from the 1st column which is where we get the using 2:3:1. It's actually a lot more powerful than that (the syntax will allow you to add 2 columns together to derive an x or y position for instance), but explaining all of that should probably be left for another question.



回答2:

Since you are using a csv file you should set the separator:

set datafile separator ','

Also, I think this is what you're trying to do:

plot 'infile' using 2:3, 'infile' 2:3:1 with labels offset 1