Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot plot labelled data

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.

like image 753
syzygy Avatar asked Mar 02 '13 04:03

syzygy


People also ask

How to label plots gnuplot?

The labels style is available only if gnuplot is built with configuration option -enable-datastrings. For a 2-D plot with labels you must specify 3 input data columns; the text string found in the third column is printed at the X and Y coordinates generated by the first two column specifiers.

How use gnuplot to plot data from a file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

How are labels and arrows helpful?

An arrow and a label are used to point out an oddity in the data . The label contains the Unicode character π (see the sidebar in section 5.1 for more information on Unicode and how to enter Unicode characters in gnuplot).

What is gnuplot QT?

QT-package. Gnuplot is a portable command-line driven interactive data and function plotting utility that supports lots of output formats, including drivers for many printers, (La)TeX, (x)fig, Postscript, and so on. Data files and self-defined functions can be manipulated by the internal C-like language.


2 Answers

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.

like image 125
mgilson Avatar answered Oct 14 '22 11:10

mgilson


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
like image 41
SidR Avatar answered Oct 14 '22 13:10

SidR