Gnuplot question

Discussion in 'General Discussions' started by Linux-SWAT, May 8, 2018.

  1. Linux-SWAT

    Linux-SWAT Hardcore Member

    Joined:
    Feb 13, 2010
    Messages:
    8,069
    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.
     

    Attached Files:

    Tags:
  2. pocak

    pocak Member

    Joined:
    Oct 11, 2009
    Messages:
    72
    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).
     
    Linux-SWAT likes this.
  3. Linux-SWAT

    Linux-SWAT Hardcore Member

    Joined:
    Feb 13, 2010
    Messages:
    8,069
    Thanks, this was helpful !
     

Share This Page

Loading...