22

I have a data file, abc.dat and I want to plot it with labeling each coordinate like (1,5), (4,6), (2,8) and so on ....

abc.dat is like :

1  5
4  6
2  8
4  5
7  8
8  9
3  4
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
hkchakladar
  • 749
  • 1
  • 7
  • 15

1 Answers1

41

Use the labels plotting style for this. That requires three using specifiers: x-value, y-value and a string which is placed at the given coordinates. So the easiest command would be:

plot 'abc.dat' using 1:2:(sprintf("(%d, %d)", $1, $2)) with labels notitle

That places the respective labels centered at the coordinates.

The following command plots a point at the respective coordinate and places the coordinate label a bit shifted near to it:

set offset 1,1,1,1
plot 'abc.dat' using 1:2:(sprintf("(%d, %d)", $1, $2)) with labels point  pt 7 offset char 1,1 notitle

The result with 4.6.4 is:

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Is there a way to control the font size of those labels? – PyariBilli Jan 17 '16 at 18:32
  • 1
    @gforce89 Use `font ',14'` or similar: `plot ... with labels point pt 7 offset char 1,1 font ',14' notitle`, you can also control the alignment with `center` or `right` – Christoph Jan 17 '16 at 18:40
  • This does not work in epslatex terminal. Is there a workaround for this? – PyariBilli Jan 18 '16 at 05:18
  • 1
    @gforce89 For epslatex you must include the respective macro call in the format: `sprintf("\large (%d, %d)", $1, $2))`. – Christoph Jan 18 '16 at 05:27
  • This doesnot seem to work. plots as large(x,y) with no reduction in size. – PyariBilli Jan 18 '16 at 06:01
  • Sorry, was too early this morning. You must escape the backslash if you have double quotes. Or you use single quotes `sprintf('\large (%d, %d)', $1, $2))` – Christoph Jan 18 '16 at 07:26
  • Still no luck. Both ways give the same wrong output – PyariBilli Jan 18 '16 at 10:23
  • 1
    Now I had time to check this: Seems like for this special constellation you must escape the backslash more often: While `set xlabel '\large xlabel'` works fine, you must use `plot ... using 1:2:(sprintf('\\large %d', $2)) w labels`, or `plot ... using 1:2:(sprintf("\\\\large %d, $2)) w labels` in this case here. – Christoph Jan 18 '16 at 11:26
  • Finally works... but a very strange rule. Does not make sense. – PyariBilli Jan 18 '16 at 19:46
  • can we have a second label below the black dot, that is to have the dot labelled above and below it?. The labels can come from a third and a fourth column respectively. – Gathide Apr 17 '17 at 11:25