English 中文(简体)
Labels on the input data in gnuplot
原标题:

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?

最佳回答

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
问题回答

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.





相关问题
Choosing line type and color in Gnuplot 4.0

I have two pairs of datasets, which I need to plot using Gnuplot. I want the first pair to be plotted in red, one solid and one dashed. The second pair, I want to plot in blue, one solid and one ...

Graph Formatting Tools For Octave

I know that Matlab allows for you to format the graph after its created through the interface. However there isn t the same features in Octave. Is there a tool that goes between Octave and GnuPlot? If ...

Labels on the input data in gnuplot

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 ...

Drawing gant-like diagram from file in C with boxes and axis

I am programming system in C and I would like to draw rectangles into 2D plain with axis X and Y to represent generated data (scheduling problems).It should LOOK LIKE gant chart. Information are ...

Treat axis as date/time (epoch)

I m generating a graph with gnuplot of activity over the last twenty four hours, but the time axis looks really bad because it s trying to fit the long number for every five minutes in the last day. ...

Gnuplot Cumulative Column Question

I have some data. #Time Distance 1 3 2 5 4 9 8 11 12 17 14 20 16 34 20 40 I want to plot the cumulative distance wrt time in gnuplot ... (it should be easy) but I do not know how. x

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

热门标签