Gnuplot question


Linux-SWAT

Forum Addict!
Joined
Feb 13, 2010
Messages
9,171
Hi,

I have this data file :
Total time
1845
1064
1056
etc.

I plot it using:
set terminal svg size 1024,768
set title 'test'
set xlabel 'try'
set ylabel 'Time (sec)'
set style data histogram
set style histogram clustered gap 1
set style fill solid 1 noborder
set xtics scale 0
plot ARG1 using 1:xtic(1) title columnheader

So I get the plot.

My question is: how do I display 1, 2, 3, etc. e.g. the line number on the x axis instead of the values ?
I tried various things without success.
I can add a 1 2 3 column and read from it but I'd like to avoid it.
 

Attachments

  • test1.png
    test1.png
    9.8 KB · Views: 184
Column zero contains the line number in gnuplot. The documentation calls it a "pseudocolumn."

So, something like xtic(stringcolumn(0)) is a start. It's a bit tricky, because if the type of xtic's argument is numeric, it gets interpreted as a column number, and if that fails, xtic does nothing without even giving a warning :-||. For example, xtic(column(0)) is ignored.

Now, the pseudocolumns are zero based, and it looks like you want a one based count. But if you do any arithmetic with a string, e.g. "1"+stringcolumn(0), it gets promoted to a numeral and xtic fails. So that's no good. We need a way to turn an integer into a string. I've only found sprintf and gprintf to do that in gnuplot.

So my solution is:
plot ARG1 using 1:xtic(sprintf("%d", $0+1)) title columnheader

$0 is shorthand for column(0).
 
Back
Top