Question

I have a datafile that looks like this

#index name1 name2 name3
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

I want to plot 3 lines:

plot "data" using 1:2 with lines,\
...

This works ok, except for the line labels. How can I specify the column names in the datafile?

Was it helpful?

Solution

If you have gnuplot 4.2 or newer, you can do this fairly easily. You will need to get rid of the comment marker in the first line though.

With a file like this:

index name1 name2 name3
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

the following will do what you want:

set key autotitle columnheader
plot 'a.dat' u 1:2 w l, '' u 1:3 w l, '' u 1:4 w l

If I do set term dumb before plotting, I get a nice ascii plot. I love gnuplot!

7 ++----------+----------+-----------+-----------+----------+---------$$$
  +           +          +           +           +         name1$****** +
  |                                                       $name2 ###### |
  |                                                 $$$$$$ name3 $$$$$$ |
6 ++                                          $$$$$$                  ###
  |                                     $$$$$$                  ######  |
  |                               $$$$$$                  ######        |
  |                         $$$$$$                  ######              |
5 ++                   $$$$$                  ######                  ***
  |              $$$$$$                 ######                  ******  |
  |        $$$$$$                 ######                  ******        |
  |  $$$$$$                 ######                  ******              |
4 $$$                  #####                  ******                   ++
  |              ######                 ******                          |
  |        ######                 ******                                |
  |  ######                 ******                                      |
3 ###                  *****                                           ++
  |              ******                                                 |
  |        ******                                                       |
  +  ******   +          +           +           +          +           +
2 ***---------+----------+-----------+-----------+----------+----------++
  1          1.5         2          2.5          3         3.5          4

OTHER TIPS

columnheader(n)

More verbose / flexible than set key autotitle columnheader:

plot 'my.dat' using 1:2 title columnheader(2), \
    '' using 1:3 title columnheader(3)

Tested on Gnuplot 4.6, Ubuntu 15.10.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top