tags:

views:

52

answers:

1

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?

+1  A: 

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
Alok